Skip to contentSkip to conversation

Fix progenyof to compare TGIDs

PATCH In review [email protected] 2 participants 2 messages Mar 28 – Apr 14

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix progenyof to compare TGIDs

From: Eugene Loh <[email protected]>

Switch the BPF progenyof helper to read TASK_TGID so it matches the process IDs returned by ppid and expand the progenyof test to cover both pid and ppid. The original tst.progenyof.d only exercised probes in the main DTrace thread where tid == tgid, so it never exposed the mismatch.

---
 bpf/progenyof.S                       |  6 +++---
 test/unittest/funcs/tst.progenyof2.sh | 31 +++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 3 deletions(-)
 create mode 100755 test/unittest/funcs/tst.progenyof2.sh
bpf/progenyof.S +3 -3
index 5b4ce60fa..8ee76e63c 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates.
+ * Copyright (c) 2022, 2026, Oracle and/or its affiliates.
  */
 
 #include <bpf_asm_helpers.h>
@@ -34,11 +34,11 @@ dt_progenyof:
 	/* if (count <= 0) goto Lret0 */
 	jsle	CNT, 0, .Lret0
 
-	/* val = *((uint32_t *)(ptr + TASK_PID)), using [%fp+-8] as temp */
+	/* val = *((uint32_t *)(ptr + TASK_TGID)), using [%fp+-8] as temp */
 	mov	%r1, %fp
 	add	%r1, -8
 	mov	%r2, 4
-	lddw	%r3, TASK_PID
+	lddw	%r3, TASK_TGID
 	add	%r3, PTR
 	call	BPF_FUNC_probe_read
 	jne	%r0, 0, .Lret0
test/unittest/funcs/tst.progenyof2.sh new file +31 -0
new file mode 100755
index 000000000..1f284cdd8
@@ -0,0 +1,31 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2026, 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/progenyof2.$$.$RANDOM"
+mkdir -p $DIRNAME
+cd $DIRNAME
+
+# make the trigger
+
+cat << EOF > a.c
+int main(void) {
+	return 0;
+}
+EOF
+$CC $test_cppflags $test_ldflags a.c
+if [ $? -ne 0 ]; then
+	echo ERROR: compiling trigger
+	exit 1
+fi
+
+# check that progenyof(ppid) and progenyof(pid) are nonzero
+
+$dtrace -c ./a.out -qn 'pid$target:a.out:main:* { exit((progenyof(ppid) && progenyof(pid)) ? 0 : 1) }'
+
+exit $?
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw

On 28 Mar 2026, eugene loh uttered the following:

Quoted 8 lines

From: Eugene Loh <[email protected]>

Switch the BPF progenyof helper to read TASK_TGID so it matches the process IDs returned by ppid and expand the progenyof test to cover both pid and ppid. The original tst.progenyof.d only exercised probes in the main DTrace thread where tid == tgid, so it never exposed the mismatch.

Quoted 15 lines
test/unittest/funcs/tst.progenyof2.sh new file +9 -0
new file mode 100755
index 000000000..1f284cdd8
@@ -0,0 +1,31 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2026, 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
+

test/unittest/funcs/tst.progenyof2.sh line 19

Quoted 10 lines
test/unittest/funcs/tst.progenyof2.sh new file +10 -0
+DIRNAME="$tmpdir/progenyof2.$$.$RANDOM"
+mkdir -p $DIRNAME
+cd $DIRNAME
+
+# make the trigger
+
+cat << EOF > a.c
+int main(void) {
+	return 0;
+}

It might in future be worth creating a thread in this test too... and having a variant which has a process which creates a thread and exec()s from that thread.

Signature · 1 line
NULL && (void)