Skip to contentSkip to conversation

Remove orphaned dtrace_recdesc_t component dtrd_uarg

PATCH In review [email protected] 3 participants 10 messages Mar 25, 2025 – Aug 13, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 Remove orphaned dtrace_recdesc_t component dtrd_uarg

From: Eugene Loh <[email protected]>

---
 include/dtrace/metadesc.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/dtrace/metadesc.h +1 -2
index 8a4add255..b0f789932 100644
@@ -2,7 +2,7 @@
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  *
- * Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
  */
 
 /*
@@ -39,7 +39,6 @@ typedef struct dtrace_recdesc {
 	uint16_t dtrd_alignment;		/* required alignment */
 	void *dtrd_format;			/* format, if any */
 	uint64_t dtrd_arg;			/* action argument */
-	uint64_t dtrd_uarg;			/* user argument */
 } dtrace_recdesc_t;
 
 typedef struct dtrace_datadesc {
Signature · 1 line
2.43.5
#1 lore raw

PATCH 2/4 test: Skip trace() of a 1-byte struct

From: Eugene Loh <[email protected]>

With commit 3a551bfd ("trace: fix char-array handling"), this test started to FAIL. Meanwhile, the behavior of trace() on a 1-byte struct is poorly defined. Users wishing clear semantics should use print() or other actions.

Skip the test.

---
 .../actions/trace/tst.struct-1-byte.d         | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)
test/unittest/actions/trace/tst.struct-1-byte.d +24 -0
index 36de485f8..8bfcbdd53 100644
@@ -5,6 +5,30 @@
  * http://oss.oracle.com/licenses/upl.
  */
 
+/*
+ * With Solaris or legacy DTrace on Linux, the script gives
+ *       52
+ * That is, contents are dumped as an integer because the trace()
+ * argument is 1, 2, 4, or 8 bytes -- specifically, it is 1 byte.
+ *
+ * Before commit 3a551bfd ("trace: fix char-array handling"), we got
+ *           0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
+ *       0: 34                                               4
+ * That is, contents were dumped as raw bytes.
+ *
+ * With that patch, we get:
+ *       4
+ * That is, contents are dumped as the string "4" since the contents
+ * are a printable char followed optionally by NUL bytes.
+ *
+ * The truth is that the semantics of trace() are poorly defined.
+ * So we are hard-pressed to say what is correct.  The test has
+ * little value.  Skip it.
+ *
+ * Users who want type-aware printing can use the print() action.
+ */
+/* @@skip: poorly defined semantics */
+
 /*
  * ASSERTION: The trace() action prints a struct { int8_t } correctly.
  *
Signature · 1 line
2.43.5
#2 lore raw

Re: [PATCH 2/4] test: Skip trace() of a 1-byte struct

On 25 Mar 2025, eugene loh outgrape:

Quoted 6 lines

From: Eugene Loh <[email protected]>

With commit 3a551bfd ("trace: fix char-array handling"), this test started to FAIL. Meanwhile, the behavior of trace() on a 1-byte struct is poorly defined. Users wishing clear semantics should use print() or other actions.

This makes trace() much, much less useful. I'd say NAK, if this means we're going to not come up with any useful behaviour. Why not define something, then use it?

Nobody is going to say "look at the size of something and then do a print() rather than a trace() if it's too small". Even looking at this commit I'm not sure what "too small" is (one byte? four bytes? sizeof(int)? sizeof(long)? A cacheline? what?) so I don't see how our users can be expected to.

author
#3 lore raw

Re: [PATCH 2/4] test: Skip trace() of a 1-byte struct

This patch is rescinded in deference to another patch that simply changes the .r file to match the current output.

Quoted 17 lines · Nick Alcock

On 25 Mar 2025, eugene loh outgrape:

Quoted 6 lines

From: Eugene Loh <[email protected]>

With commit 3a551bfd ("trace: fix char-array handling"), this test started to FAIL. Meanwhile, the behavior of trace() on a 1-byte struct is poorly defined. Users wishing clear semantics should use print() or other actions.

This makes trace() much, much less useful. I'd say NAK, if this means we're going to not come up with any useful behaviour. Why not define something, then use it?

Nobody is going to say "look at the size of something and then do a print() rather than a trace() if it's too small". Even looking at this commit I'm not sure what "too small" is (one byte? four bytes? sizeof(int)? sizeof(long)? A cacheline? what?) so I don't see how our users can be expected to.

#4 lore raw

PATCH 3/4 test: Update some char-array results files

In reply to [email protected]

From: Eugene Loh <[email protected]>

A few tests started failing with commit 3a551bfd ("trace: fix char-array handling"). Update the results files to reflect older behavior, whether on Solaris or with the legacy Linux DTrace implementation.

Notice that test/unittest/funcs/substr/tst.substr-large-idx.d specifies strsize=256. The older behavior would result in 256 chars being shown. We add a results file that includes a 257th char.

---
 .../funcs/substr/tst.substr-large-idx.r       | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
test/unittest/funcs/substr/tst.substr-large-idx.r +19 -0
index 8b1378917..79fecbd32 100644
@@ -1 +1,20 @@
 
+             0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
+         0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+        f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
+       100: 00                                               .
+
Signature · 1 line
2.43.5
#5 lore raw

Re: [PATCH 3/4] test: Update some char-array results files

Quoted 6 lines · eugene loh

From: Eugene Loh <[email protected]>

A few tests started failing with commit 3a551bfd ("trace: fix char-array handling"). Update the results files to reflect older behavior, whether on Solaris or with the legacy Linux DTrace implementation.

I think this commit didn't get reviewed because nobody understood what this meant. If tests started failing, why adjust the results to reflect *older* behaviour (presumably "before that change"?)

Or do you mean that commit 3a551bfd adjusted trace() to work like it historically did, but one test was missed and needs correspondingly adjusting?

Quoted 4 lines

Notice that test/unittest/funcs/substr/tst.substr-large-idx.d specifies strsize=256. The older behavior would result in 256 chars being shown. We add a results file that includes a 257th char.

(the trailing NUL, presumably.)

author
#6 lore raw

Re: [PATCH 3/4] test: Update some char-array results files

Quoted 9 lines · Nick Alcock
Quoted 6 lines · eugene loh

From: Eugene Loh <[email protected]>

A few tests started failing with commit 3a551bfd ("trace: fix char-array handling"). Update the results files to reflect older behavior, whether on Solaris or with the legacy Linux DTrace implementation.

I think this commit didn't get reviewed because nobody understood what this meant.

There might be other issues.  There may be broader issues here about how we should handle strings.  But, I guess here we can focus on this patch.

Quoted 6 lines

If tests started failing, why adjust the results to reflect *older* behaviour (presumably "before that change"?)

Or do you mean that commit 3a551bfd adjusted trace() to work like it historically did, but one test was missed and needs correspondingly adjusting?

The 3a551bf patch made this test fail, but changing the .r file as indicated works both for historical behavior and for this new patch (modulo the 256/257 issue).  So, "yes" to your "Or do you mean?" question.  Would a change of commit message wording get your R-b? I'm not sure what to change since I thought it was evident from the patch what was going on.

Quoted 5 lines
Quoted 4 lines

Notice that test/unittest/funcs/substr/tst.substr-large-idx.d specifies strsize=256. The older behavior would result in 256 chars being shown. We add a results file that includes a 257th char.

(the trailing NUL, presumably.)

#7 lore raw

PATCH 4/4 Pad strings in the output buffer with NUL bytes after terminating byte

In reply to [email protected]

From: Eugene Loh <[email protected]>

The consumer checks if there are non-NUL bytes after the terminating NUL byte to decide whether to print the contents of the output buffer as a string or as raw bytes. So, for strings, make sure that the string is padded with NUL bytes.

A robust test that shows the problem can be hard to devise. Some tests encounter the problem. This patch adds another test that might show the problem.

---
 libdtrace/dt_cg.c                      | 46 ++++++++++++++++++--------
 test/unittest/error/tst.trace_string.d | 26 +++++++++++++++
 2 files changed, 59 insertions(+), 13 deletions(-)
 create mode 100644 test/unittest/error/tst.trace_string.d
libdtrace/dt_cg.c +33 -13
index 9b3592b9c..6dcf4cd3d 100644
@@ -1596,6 +1596,22 @@ dt_cg_check_ptr_arg(dt_irlist_t *dlp, dt_regset_t *drp, dt_node_t *dnp,
 
 static void dt_cg_setx(dt_irlist_t *dlp, int reg, uint64_t x);
 
+/*
+ * Store a pointer to the 'memory block of zeros' in reg.
+ */
+static void
+dt_cg_zerosptr(int reg, dt_irlist_t *dlp, dt_regset_t *drp)
+{
+	dtrace_hdl_t	*dtp = yypcb->pcb_hdl;
+	dt_ident_t	*zero_off = dt_dlib_get_var(dtp, "ZERO_OFF");
+
+	dt_cg_access_dctx(reg, dlp, drp, DCTX_STRTAB);
+	emite(dlp, BPF_ALU64_IMM(BPF_ADD, reg, -1), zero_off);
+}
+
+/*
+ * Store a value to the output buffer.
+ */
 static int
 dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
 		dt_pfargv_t *pfp, int arg)
@@ -1676,6 +1692,7 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
 
 		goto ok;
 	} else if (dt_node_is_string(dnp)) {
+		uint_t	lbl_ok = dt_irlist_label(dlp);
 		size_t	strsize = dtp->dt_options[DTRACEOPT_STRSIZE];
 
 		if (!not_null)
@@ -1702,6 +1719,22 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
 		dt_regset_xalloc(drp, BPF_REG_0);
 		emit(dlp, BPF_CALL_HELPER(BPF_FUNC_probe_read_str));
 		dt_regset_free_args(drp);
+
+		/*
+		 * Pad the rest with zeroes, if necessary.
+		 */
+		emit(dlp,  BPF_BRANCH_IMM(BPF_JGE, BPF_REG_0, strsize + 1, lbl_ok));
+		if (dt_regset_xalloc_args(drp) == -1)
+			longjmp(yypcb->pcb_jmpbuf, EDT_NOREG);
+		emit(dlp,  BPF_MOV_REG(BPF_REG_1, BPF_REG_9));
+		emit(dlp,  BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, off));
+		emit(dlp,  BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0));
+		emit(dlp,  BPF_MOV_IMM(BPF_REG_2, strsize + 1));
+		emit(dlp,  BPF_ALU64_REG(BPF_SUB, BPF_REG_2, BPF_REG_0));
+		dt_cg_zerosptr(BPF_REG_3, dlp, drp);
+		emit(dlp,  BPF_CALL_HELPER(dtp->dt_bpfhelper[BPF_FUNC_probe_read_kernel]));
+		dt_regset_free_args(drp);
+		emitl(dlp, lbl_ok, BPF_NOP());
 		dt_regset_free(drp, BPF_REG_0);
 		TRACE_REGSET("store_val(): End   ");
 
@@ -3042,19 +3075,6 @@ dt_cg_pop_stack(int reg, dt_irlist_t *dlp, dt_regset_t *drp)
 	dt_regset_free(drp, treg);
 }
 
-/*
- * Store a pointer to the 'memory block of zeros' in reg.
- */
-static void
-dt_cg_zerosptr(int reg, dt_irlist_t *dlp, dt_regset_t *drp)
-{
-	dtrace_hdl_t	*dtp = yypcb->pcb_hdl;
-	dt_ident_t	*zero_off = dt_dlib_get_var(dtp, "ZERO_OFF");
-
-	dt_cg_access_dctx(reg, dlp, drp, DCTX_STRTAB);
-	emite(dlp, BPF_ALU64_IMM(BPF_ADD, reg, -1), zero_off);
-}
-
 /*
  * Generate code to promote signed scalars (size < 64 bits) to native register
  * size (64 bits).
test/unittest/error/tst.trace_string.d new file +26 -0
new file mode 100644
index 000000000..4b06aef88
@@ -0,0 +1,26 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, 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: Test ERROR probe firing.
+ *
+ * SECTION: dtrace Provider
+ */
+
+#pragma D option quiet
+
+ERROR
+{
+	trace("Error fired");
+	exit(0);
+}
+
+BEGIN
+{
+	*(char *)NULL;
+	exit(1);
+}
Signature · 1 line
2.43.5
Reviewed-by on v1 4/4
#8 lore raw

Re: [PATCH 4/4] Pad strings in the output buffer with NUL bytes after terminating byte

On 25 Mar 2025, eugene loh uttered the following:

Quoted 6 lines

From: Eugene Loh <[email protected]>

The consumer checks if there are non-NUL bytes after the terminating NUL byte to decide whether to print the contents of the output buffer as a string or as raw bytes. So, for strings, make sure that the string is padded with NUL bytes.

Ugh. I guess there's no choice if we want trace() to work properly.

A use for strncpy()! except that this is BPF :)

Quoted 1 line

because basing decisions on uninitialized data is bad.

(Modulo nit below.)

Quoted 49 lines
---
 libdtrace/dt_cg.c                      | 46 ++++++++++++++++++--------
 test/unittest/error/tst.trace_string.d | 26 +++++++++++++++
 2 files changed, 59 insertions(+), 13 deletions(-)
 create mode 100644 test/unittest/error/tst.trace_string.d
libdtrace/dt_cg.c +21 -0
index 9b3592b9c..6dcf4cd3d 100644
@@ -1596,6 +1596,22 @@ dt_cg_check_ptr_arg(dt_irlist_t *dlp, dt_regset_t *drp, dt_node_t *dnp,
 
 static void dt_cg_setx(dt_irlist_t *dlp, int reg, uint64_t x);
 
+/*
+ * Store a pointer to the 'memory block of zeros' in reg.
+ */
+static void
+dt_cg_zerosptr(int reg, dt_irlist_t *dlp, dt_regset_t *drp)
+{
+	dtrace_hdl_t	*dtp = yypcb->pcb_hdl;
+	dt_ident_t	*zero_off = dt_dlib_get_var(dtp, "ZERO_OFF");
+
+	dt_cg_access_dctx(reg, dlp, drp, DCTX_STRTAB);
+	emite(dlp, BPF_ALU64_IMM(BPF_ADD, reg, -1), zero_off);
+}
+
+/*
+ * Store a value to the output buffer.
+ */
 static int
 dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
 		dt_pfargv_t *pfp, int arg)
@@ -1676,6 +1692,7 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
 
 		goto ok;
 	} else if (dt_node_is_string(dnp)) {
+		uint_t	lbl_ok = dt_irlist_label(dlp);
 		size_t	strsize = dtp->dt_options[DTRACEOPT_STRSIZE];
 
 		if (!not_null)
@@ -1702,6 +1719,22 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
 		dt_regset_xalloc(drp, BPF_REG_0);
 		emit(dlp, BPF_CALL_HELPER(BPF_FUNC_probe_read_str));
 		dt_regset_free_args(drp);
+
+		/*
+		 * Pad the rest with zeroes, if necessary.
+		 */

libdtrace/dt_cg.c dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind, · line 1735

Quoted 10 lines
libdtrace/dt_cg.c +10 -0
+		emit(dlp,  BPF_BRANCH_IMM(BPF_JGE, BPF_REG_0, strsize + 1, lbl_ok));
+		if (dt_regset_xalloc_args(drp) == -1)
+			longjmp(yypcb->pcb_jmpbuf, EDT_NOREG);
+		emit(dlp,  BPF_MOV_REG(BPF_REG_1, BPF_REG_9));
+		emit(dlp,  BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, off));
+		emit(dlp,  BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0));
+		emit(dlp,  BPF_MOV_IMM(BPF_REG_2, strsize + 1));
+		emit(dlp,  BPF_ALU64_REG(BPF_SUB, BPF_REG_2, BPF_REG_0));
+		dt_cg_zerosptr(BPF_REG_3, dlp, drp);
+		emit(dlp,  BPF_CALL_HELPER(dtp->dt_bpfhelper[BPF_FUNC_probe_read_kernel]));

Much faster than using a loop in all but the smallest cases, I suppose. (And the zero block is presumably always big enough... yes, it is.)

Quoted 6 lines
test/unittest/error/tst.trace_string.d new file +0 -0
new file mode 100644
index 000000000..4b06aef88

test/unittest/error/tst.trace_string.d line 9

Quoted 9 lines
test/unittest/error/tst.trace_string.d new file +9 -0
@@ -0,0 +1,26 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, 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: Test ERROR probe firing.

... is that really what you want to describe this test as?

test/unittest/error/tst.trace_string.d line 18

Quoted 8 lines
test/unittest/error/tst.trace_string.d new file +8 -0
+ * SECTION: dtrace Provider
+ */
+
+#pragma D option quiet
+
+ERROR
+{
+	trace("Error fired");

.... given that its stated purpose is quite different, why not describe that purpose?

Reviewed-by on v1 1/4
#9 lore raw
In reply to [email protected]
Quoted 3 lines · On Tue, Mar 25, 2025 at 06:25:18PM -0400, [email protected] wrote:

From: Eugene Loh <[email protected]>

Quoted 28 lines
---
 include/dtrace/metadesc.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/dtrace/metadesc.h +1 -2
index 8a4add255..b0f789932 100644
@@ -2,7 +2,7 @@
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  *
- * Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
  */
 
 /*
@@ -39,7 +39,6 @@ typedef struct dtrace_recdesc {
 	uint16_t dtrd_alignment;		/* required alignment */
 	void *dtrd_format;			/* format, if any */
 	uint64_t dtrd_arg;			/* action argument */
-	uint64_t dtrd_uarg;			/* user argument */
 } dtrace_recdesc_t;
 
 typedef struct dtrace_datadesc {
Signature · 1 line
2.43.5