Re: [PATCH net-next v4 14/14] selftests: dpll: add reference leak tests

From
netdev-bot+sashiko@kernel.org
Date
2026-11-16 14:30:14
Also in
linux-doc, linux-kselftest
Reply to
Petr Oros, 2026-11-12
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message says the stress script's final leak check "is
  skipped when an earlier test left a device behind", but the skip only…
- [Low] In dpll_reftrack.sh, test_basic_reftrack carries on to
  dpll_ref_tracker_check_leaks after destroy_device has failed.
- [Low] The leak check can miss a leaking object because of the
  asynchronous ref_tracker reap work.
- [Low] __dpll_ref_tracker_new_entries counts a new entry as a leak only
  if reading it returns content (`[ -n "$content" ] || continue`,…

--

selftests: dpll: add reference leak tests

This patch adds helpers to dpll_lib.sh that snapshot the DPLL ref_tracker
debugfs entries and report non-empty entries that are not in the
snapshot as leaks. A throwaway dpllsim device probes whether the tracker
works. The new dpll_reftrack.sh uses the helpers, dpll_stress.sh gains a
final leak check, and the selftest config enables
CONFIG_DPLL_REFCNT_TRACKER and the options it needs.
quoted hunk ↗ jump to hunk
diff --git a/tools/testing/selftests/drivers/dpll/dpll_lib.sh b/tools/testing/selftests/drivers/dpll/dpll_lib.sh
index 1dfe15943f343..f7bfe046edf93 100644
--- a/tools/testing/selftests/drivers/dpll/dpll_lib.sh
+++ b/tools/testing/selftests/drivers/dpll/dpll_lib.sh
[ ... ]
quoted hunk ↗ jump to hunk
@@ -719,3 +736,254 @@ dpllsim_setup_standard_device()
 		return 1
 	fi
 }
+
+##############################################################################
+# ref_tracker leak checking
+#
+# With CONFIG_DPLL_REFCNT_TRACKER=y the DPLL core creates regular files
+# named dpll_device@<ptr> / dpll_pin@<ptr> under the ref_tracker debugfs
+# dir. Reading one prints the stack traces of currently unreleased
+# references; an empty (or removed) file means no leaks.
[Severity: Low]
Does "an empty (or removed) file means no leaks" match how ref_tracker
behaves?

In lib/ref_tracker.c, ref_tracker_dir_exit() marks the dir
REF_TRACKER_DIR_DEAD before the object is freed. From then until the reap
work removes the file, ref_tracker_debugfs_show() returns -ENODATA:

    if (!xa_load(&debugfs_dentries, index) ||
        xa_get_mark(&debugfs_dentries, index, REF_TRACKER_DIR_DEAD)) {
        xa_unlock_irqrestore(&debugfs_dentries, flags);
        return -ENODATA;
    }

That means a file that reads back successfully but empty belongs to an
object that is still alive. __ref_tracker_dir_pr_ostream() prints nothing
when dir->list is empty. That happens when the refcount is held through
no_tracker or untracked holds, or after an imbalance where the tracker
was freed but the refcount was not dropped.

__dpll_ref_tracker_new_entries() below treats a readable empty entry the
same as an unreadable one:

    content=$(cat "$entry" 2>/dev/null)
    [ -n "$content" ] || continue

Could that kind of object leak pass both dpll_reftrack.sh and the final
check in dpll_stress.sh? No in-tree caller seems to pass a NULL tracker
today, so this is about catching a future regression.

Counting every readable entry that is not in the snapshot as a leak
would close the gap. Entries waiting for the reap would still be skipped.

[ ... ]
quoted hunk ↗ jump to hunk
+__dpll_ref_tracker_new_entries()
+{
+	local file=$1
+	local entry name content
+
+	for entry in "$DPLL_REF_TRACKER_DIR"/dpll_device@* \
+		     "$DPLL_REF_TRACKER_DIR"/dpll_pin@*; do
+		[ -f "$entry" ] || continue
+		name=$(basename "$entry")
+		grep -q "^$name " "$file" && continue
+		content=$(cat "$entry" 2>/dev/null)
+		[ -n "$content" ] || continue
[Severity: Low]
Can the asynchronous reap in ref_tracker cause this check to miss a
leaking object?

__dpll_device_put() calls ref_tracker_dir_exit() and then kfree(dpll)
straight away:

    ref_tracker_dir_exit(&dpll->refcnt_tracker);
    kfree(dpll);

ref_tracker_dir_exit() only sets REF_TRACKER_DIR_DEAD and schedules
debugfs_reap_worker. Suppose dpll_device_alloc() returns the same address
before the reap work runs. Then
ref_tracker_dir_init()->ref_tracker_dir_debugfs() finds the old dentry
and creates no file:

    /* No-op if already created */
    dentry = xa_load(&debugfs_dentries, (unsigned long)dir);
    if (dentry && !xa_is_err(dentry))
        return;

Reads of the old file then return -ENODATA, even though a live object
now owns that address. Once the reap work runs, the file is removed, and
the new object has no entry at all.

The cat above fails quietly and the entry is skipped. A leak in that
object would then never show up in test_ref_leaks() or
test_final_leak_check(). In test_concurrent_workers(), several processes
create and delete devices in tight loops, which gives exactly this
free-then-allocate pattern.

ref_tracker_dir_debugfs() was already missing the DEAD check before this
patch, but the new leak check depends on that function and inherits the
blind spot. The commit message lists the other limitations it accepts.
Should this one be listed there too?
quoted hunk ↗ jump to hunk
+		echo "Unreleased references in $name:"
+		echo "$content"
+	done
+}
[ ... ]
quoted hunk ↗ jump to hunk
diff --git a/tools/testing/selftests/drivers/dpll/dpll_reftrack.sh b/tools/testing/selftests/drivers/dpll/dpll_reftrack.sh
new file mode 100755
index 0000000000000..f2871b5ad8472
--- /dev/null
+++ b/tools/testing/selftests/drivers/dpll/dpll_reftrack.sh
@@ -0,0 +1,190 @@
[ ... ]
quoted hunk ↗ jump to hunk
+test_basic_reftrack()
+{
+	RET=0
+
[ ... ]
quoted hunk ↗ jump to hunk
+	CREATED_DEVICE=$DPLLSIM_CREATED_NAME
+
+	destroy_device
+	check_err $? "cannot delete device $CREATED_DEVICE"
+
+	if ! dpll_device_wait_gone_by_clock_id "$DPLLSIM_CLOCK_ID" dpllsim; then
+		check_err 1 "device still on netlink after delete"
+	fi
+
+	dpll_ref_tracker_check_leaks "$REF_SNAPSHOT"
+	check_err $? "leaked references after device removal"
[Severity: Low]
If destroy_device() fails, should test_basic_reftrack() still go on to
dpll_ref_tracker_check_leaks()?

When the undeploy fails, the device is still registered, so its normal
references show up as new, non-empty entries. The check then waits the
full BUSYWAIT_TIMEOUT and prints "References not released within ... ms"
with stack traces for a device that is still live.

test_final_leak_check() and test_ref_leaks() skip on purpose in this
situation ("the failure to report is that one"). retmsg keeps the first
message, so it still shows the delete failure. The leak dump and the
delay still happen, though.

A separate point: test_final_leak_check() runs the same check against the
same snapshot, and nothing is created or destroyed in between.
__dpll_ref_tracker_note_changed() only rewrites lines that are already in
the snapshot. So a real leak found by test_basic_reftrack() would be
reported again by test_final_leak_check(), after another
BUSYWAIT_TIMEOUT.

What is the second check meant to catch that the first one does not?

[ ... ]
quoted hunk ↗ jump to hunk
diff --git a/tools/testing/selftests/drivers/dpll/dpll_stress.sh b/tools/testing/selftests/drivers/dpll/dpll_stress.sh
index 2abfacc43b48b..226e2767ee897 100755
--- a/tools/testing/selftests/drivers/dpll/dpll_stress.sh
+++ b/tools/testing/selftests/drivers/dpll/dpll_stress.sh
[ ... ]
quoted hunk ↗ jump to hunk
@@ -496,16 +563,44 @@ test_deploy_cycle()
 	log_test "DPLL deploy/undeploy cycling"
 }
 
+test_ref_leaks()
+{
+	RET=0
+
[ ... ]
quoted hunk ↗ jump to hunk
+	# A device an earlier test could not remove still holds its
+	# references, the failure to report is that one.
+	if [ "${#CREATED_DEVICES[@]}" -gt 0 ]; then
+		log_test_skip "DPLL stress ref_tracker check" \
+			      "device from an earlier test still present"
+		return
+	fi
[Severity: Low]
The commit message says the final leak check "is skipped when an earlier
test left a device behind". Is every leftover device actually in
CREATED_DEVICES?

The workers in test_concurrent_workers() run in subshells and never call
track_device(). delete_worker_devices() only logs a failed delete:

    dpllsim_delete_device "$name" ||
        log_info "cannot delete device $name"

After that, test_concurrent_workers() clears the list whatever the
result was:

    for base in "${WORKER_BASES[@]}"; do
        delete_worker_devices "$base"
    done
    WORKER_BASES=()

dpllsim_setup_standard_device() and create_stress_device() also roll back
with dpllsim_delete_device() and ignore its result:

    if ! DPLLSIM_DEV_ID=$(dpll_device_wait_by_clock_id "$clock_id" \
                              dpllsim); then
        dpllsim_delete_device "$name"
        return 1
    fi

If that undeploy fails, DPLLSIM_CREATED_NAME is the only record of the
live device. test_final_leak_check() in dpll_reftrack.sh has the same
gap. It checks only CREATED_DEVICE, and that is set only after
dpllsim_setup_standard_device() succeeds.

In these cases dpll_ref_tracker_check_leaks() waits out BUSYWAIT_TIMEOUT.
It then reports the device's ordinary references as "leaked DPLL
references after stress" or "leaked DPLL references at end of test".

dpll_lib_cleanup() in this patch finds leftovers by scanning
"$DPLLSIM_CFG"/*/. Would the same scan work for these skips?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112130359.840795-1-poros%40redhat.com
Thread (23 messages) 23 messages, 2 authors, last reply 14h ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help