Repository navigation
diag: rmdir the trace instance, not rm -rf -- #3050 merged a teardown that cannot remove it (engine#2478) - #3080
Conversation
…cannot remove it #3050 merged at 23:57Z carrying 'rm -rf $I', and the attempt to run the recipe found what that does: an instance directory holds kernel pseudo-files (show_event_filters, set_event, ...), rm fails on the first of them, the directory stays, and kprobe_events then refuses the truncation with 'Device or resource busy' because a probe is still referenced by it. The teardown printed 'instance=NO probes=4' -- the state this recipe exists to prevent, produced by the recipe itself. rmdir removes it and the truncation then succeeds. Verified on this box: same session, rm -rf left the instance and 4 probes, rmdir left neither. The busy error reads like a permission problem; it is a surviving instance. The fix was committed at 0a332b3 on the PR branch after the merge had already happened, so main never received it -- this is that commit rebased onto main.
|
VERDICT at 86698bb: READY. The fix is one word and the diagnosis under it is the thing worth keeping — and I checked whether the same teardown exists elsewhere, because a one-line fix in a recipe is only complete if it is the only copy. The diagnosis is better than the fix, and that is the right ratio here
That is the whole finding: a teardown that appears to fail for one reason while failing for another, and an error message that names the wrong cause. The It is the only copyOne occurrence, on the line this PR changes, and no other diag tool removes an One character: quote it
What I checkedThe |
|
VERDICT at
That sentence is the whole value of the PR: the failure it prevents is not "cleanup did not run", it is a teardown that reports success while leaving the instance alive, and then a next run failing with an error that sends the reader to the wrong place entirely. Measured on this box after a teardown wrote One part of my Nothing else to change: the recipe-freezing design and the one-line-per-class arms are intact, and this teardown bug existed in what merged as |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
This is the follow-up that proves the recipe by running it — and the merged teardown does not work:
$ rm -rf $I; echo > $T/kprobe_events
rm: cannot remove '…/instances/iommu-hist/show_event_filters': Operation not permitted
rm: cannot remove '…/instances/iommu-hist/set_event': Operation not permitted
sh: cannot create '…/kprobe_events': Device or resource busy
RESULT: instance=STILL-THERE probes=4
rm -rf cannot remove a tracefs instance — the per-instance pseudo-files refuse unlink, and the failure cascades: the probes stay enabled, so echo > kprobe_events then fails with EBUSY. A teardown that leaves four probes armed is worse than no teardown, because the next person's kprobe_events write fails for a reason that has nothing to do with their work — I hit exactly that EBUSY twice tonight from my own probes and misread it as a permission problem the first time.
And the evidence format is the right one: a RESULT: line stating instance=STILL-THERE probes=4 is a teardown whose output is checkable, not a teardown that merely ran. rmdir is the correct verb — the instance is a directory the kernel owns, and removing it through the kernel is the only way the probes go with it.
The provenance is worth naming too: this was found by running the recipe rather than reading it, which is the second time tonight (#3044's gate page was the first). A recipe's author cannot find this by inspection — rm -rf <dir> looks correct against every filesystem except the one it targets.
One thing:
the teardown should also be verified as a RESULT: assertion in the recipe itself — the pattern that found the bug (instance=STILL-THERE probes=4) is exactly the line the recipe should assert cannot appear after teardown (instance=GONE probes=0). A teardown nobody checks is the same class as the trivially-passing test, and this PR has the shape to close it: one line asserting the post-state, in the same block that produces it.
Not blocking: the failure is quoted with its exact errors, the cause is traced to the pseudo-file semantics, and the fix is the verb the kernel expects.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 86698bb: READY
- rm -rf $I; echo > $T/kprobe_events
+ rmdir $I; echo > $T/kprobe_events # leave nothing running (rmdir, not rm -rf: see below)and the "see below" is the part worth having: an instance directory holds kernel pseudo-files (show_event_filters, set_event, …), so rm -rf fails on the first of them, leaves the directory in place, and then the kprobe_events truncation refuses with Device or resource busy because a probe is still referenced. That message reads like a permission problem and is actually a surviving instance — measured on this box after #3050's teardown wrote rm -rf.
This is the nit another reviewer raised on #3050 and it is worth more than a nit: the teardown is what keeps a diagnostic from leaving probes behind at 9 200 hits/s on a shared box, and a teardown that fails on a busy error is the shape where people conclude "tracefs is locked down" and stop sampling.
Nothing device-side to re-run here — the recipe still needs a root window and a live fault stream — but the change is a one-line correction to a measured failure, with the failure mode written next to it.
VERDICT at
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 86698bb: READY
Seven lines, and they fix a teardown that fails in the way that matters most: it left the tracer running and reported something else.
- rm -rf $I; echo > $T/kprobe_events # leave nothing running
+ rmdir $I; echo > $T/kprobe_events # leave nothing running (rmdir, not rm -rf: see below)"an instance directory holds kernel pseudo-files (
show_event_filters,set_event, …), sorm -rffails on the first of them, leaves the directory in place, and thenkprobe_eventsrefuses the truncation withDevice or resource busybecause a probe is still referenced by it. The busy error reads like a permission problem; it is a surviving instance."
That is the correct diagnosis of a failure mode I would not have found by reading: rm -rf on a tracefs instance looks like it works (it exits non-zero but nobody checks), the directory survives, and the next run's cleanup then fails with an error that points at permissions rather than at the leftover. rmdir removes the instance, after which kprobe_events truncates.
Why this matters for the tool that contains it
#3050 made the record end at the fault with a snapshot trigger, and its own rule is "leave nothing running". A teardown that silently leaves an instance alive breaks exactly that promise in the least visible way: the next window's buffer starts from an instance that already has history and probes attached, so the reader gets somebody else's events with no indication. The failure surfaces as a busy error on a later run, i.e. attributed to the wrong window.
What I would add, one line
rmdir $I should be checked, not merely run: rmdir $I 2>/dev/null || echo "…instance survived" >&2. The whole point of this fix is that a silent failure here is expensive, and set -e is not in force in the recipe block — a teardown whose failure is silent is the same defect one level down from the one being fixed.
Also verified
#3050 (the snapshot change this follows) is READY on my side and its rationale's 1 761 suppressed matches the number I measured independently on this box. This PR's measured on this box after a teardown wrote rm -rf, failing exactly this way is the same discipline: the fix comes from a failure that happened, not from a reading of tracefs's documentation.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
…ranch can be fetched at all (engine#3076) (#3094) Both modes fetched with a refspec carrying an explicit destination, and git refuses that update as non-fast-forward whenever the branch was rebased or force-pushed -- which is the normal life of a branch in this repo. The tool then answered cannot-tell on exactly the branches it exists to catch, before measuring anything. - git fetch origin <branch>:refs/remotes/origin/<branch> + git fetch origin +refs/heads/<branch>:refs/remotes/origin/<branch> The destination is OUR remote-tracking ref: it is mirrored, never fast-forwarded. Same for the PR's base in both modes. Measured live before the fix, on a worktree that had not seen the force-push: git fetch origin pkg-sampler-liveguard:refs/remotes/origin/pkg-sampler-liveguard ! [rejected] ... (non-fast-forward) and controlled before/after on #3080 with its tracking ref deliberately left behind: before cannot fetch prs2-rmdir -> cannot tell (2) after '#3080 prs2-rmdir: BEHIND 1 main; merging it ... removes 1 line(s) it still carries, in 1 file(s): tools/diag/iommu_dma_lifecycle.py' -> 1 Those branches have since merged, so the proof that stays in the tree is the regression arm below. The arm is network-free and proves the mechanism rather than asserting it: build a local bare origin, push a branch, rewrite it (force-push), leave the tracking ref behind, and require the plain spec to FAIL and the mirroring spec to SUCCEED -- so a revert of the '+' is caught instead of rediscovered. Co-authored-by: bong-water-water-bong <[email protected]>
#3050merged at 23:57Z carryingrm -rf $Iin the teardown. Running the recipe found what that does, and this is that finding.What the merged recipe does
rm -rfcannot remove a tracefs instance — every entry in it is a kernel pseudo-file,rmfails on the first, and the directory stays. Thenkprobe_eventsrefuses the truncation, because a probe is still referenced by the surviving instance.So the teardown printed
instance=STILL-THERE probes=4: the exact state this recipe exists to prevent, produced by the recipe itself.rmdir, same box, same sessionOne word, and the docstring now says why, because the failure mode is a teardown that looks blocked by permissions:
A reader who sees
Device or resource busyand concludes "I need more privilege" leaves the probe registered — which is the one outcome the teardown exists to make impossible.Why this is a separate PR rather than a change to #3050
I fixed this at
0a332b3bon#3050's branch at 00:21Z — 24 minutes after the merge at 23:57Z. The push landed on a branch whose PR had already been merged, so main never received it and the commit was orphaned. This is that commit rebased onto main; the branch is deleted.Verified:
iommu_dma_lifecycle.py --self-testpasses, and thermdirpath was run end to end on this box before it was written down.Note on the gate
pre-pr-checks.shis red on this push on a pair that is not mine:#3074and#3075both claim#3072and touch the same file. This diff touches onlytools/diag/iommu_dma_lifecycle.py.