Skip to content

diag: the kprobe recipe freezes the ring on the fault, because a plain ring holds one second (engine#2478) - #3050

Merged
bong-water-water-bong merged 2 commits into
mainfrom
prs2-recipe3
Nov 20, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
prs2-recipe3

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

engine#2478. The recipe in iommu_dma_lifecycle.py enabled a 64 MB ring and told the reader to cat trace after a window. Measured on this box, that holds one to two seconds of history — so the burst it exists to capture has been evicted before anyone reads it.

The measurement

  4 kprobes in a 40 s window, box otherwise idle (iommu_map / iommu_unmap_fast / __iommu_dma_unmap / report_iommu_fault)
    iommu_map          73 724     1 843 /s    110 586 /min
    iommu_unmap_fast   75 924     1 898 /s
    __iommu_dma_unmap  73 728     1 843 /s
    report_iommu_fault      0

  a 64 MB ring held 223 376 events in ~40 s  ->  1-2 s of history

What changed

mkdir -p /sys/kernel/tracing/instances/iommu-hist     # per instance: buffer, enable and triggers
I=/sys/kernel/tracing/instances/iommu-hist
T=/sys/kernel/tracing                                 # kprobe_events is GLOBAL, not per instance
…
echo 65536 > $I/buffer_size_kb
echo 'snapshot' > $I/events/kprobes/pf/trigger        # a FAULT freezes the buffer
echo 1 > $I/events/kprobes/enable; echo 1 > $I/tracing_on
… wait for the fault …
cat $I/snapshot > TRACE                               # the history ENDING at the fault
echo 0 > $I/tracing_on; echo 0 > $I/events/kprobes/enable
rm -rf $I; echo > $T/kprobe_events                    # leave nothing running

Three things the old recipe got wrong beyond the size, all found while verifying this on the box:

  • kprobe_events is global. A dedicated instance gives you per-instance buffer, enable and triggers — but not probe definitions; writing instances/<n>/kprobe_events fails.
  • snapshot:count=1 is not accepted (count= is hist-trigger syntax). Bare snapshot reads back as snapshot:unlimited, which is also the behaviour wanted: every fault re-snapshots, so the latest burst is the one preserved. A count would stop snapshotting after the first fault.
  • The teardown is part of the recipe, because the map/unmap probes fire ~9 200 times per second: a window is measured in seconds, then the instance is removed and kprobe_events emptied. A standing version of this is a hot-path cost on a shared box.

Why the kernel log is not a substitute

It has two independent truncations, both visible in it — this is what the docstring now records:

mechanism line effect
printk rate limiting amd_iommu_report_page_fault: N callbacks suppressed 1 761 suppressed against 323 printed on the boot measured (5.5×)
the IOMMU event log AMD-Vi: IOMMU Event log restarting the readable set stops at the burst

A kprobe counts before both. On this boot the second one showed up concretely: ten faults, then Event log restarting as the eleventh line of the same second.

Verified

  • The recipe was executed on this box before being written down: instance created, p:pf registered, trigger reading back snapshot:unlimited, enable ok — then instance removed and kprobe_events back to 0 lines.
  • The tool's self-test still passes (dwell, paired/unpaired classification and cannot-tell all behave), and pre-pr-checks.sh is green.

…n ring holds one second

Measured on this box 2026-11-20: the DMA path runs about 1 843 iommu_map calls per second -- 110 586 per minute --
so the 64 MB ring the recipe used to enable held 223 376 events in 40 s, i.e. one to two seconds of history. A
ring read after a burst is therefore looking at the wrong second, and the burst it was meant to capture has
already been evicted.

The recipe now uses a per-instance ring (kprobe_events is GLOBAL; instances carry buffer, enable and triggers)
with 'echo snapshot' on the fault probe, so the fault itself freezes the buffer and the record is the window
before it. 'snapshot:count=1' is not accepted -- that is hist-trigger syntax -- and a count would stop
snapshotting after the first fault, which is the opposite of what a burst needs.

Also records why the kernel log is not a substitute: printk folds repeated faults into one 'N callbacks
suppressed' line (1761 suppressed against 323 printed on the boot measured), and a large burst ends with
'AMD-Vi: IOMMU Event log restarting', so the readable set stops at the driver's log boundary. A kprobe counts
before both.

The teardown is part of the recipe: the map/unmap probes fire ~9 200 times per second, so a window is measured in
seconds and then removed; kprobe_events is emptied and the instance deleted.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 392dd0e: CHANGES on one paragraph — the recipe is right, its numbers contradict themselves by 20-40×

Everything mechanical in the new recipe checks out, and the two "beyond the size" findings are correct:

  • kprobe_events is global — true: instances/<n>/kprobe_events does not exist; probe definitions are one global list, while buffer_size_kb, enable, trigger and trace/snapshot are per instance. Writing T=/sys/kernel/tracing for the probes and I=…/instances/iommu-hist for everything else is the correct split.
  • snapshot on an event trigger is the right mechanism, and count= is hist-only — also correct; bare snapshot reading back as snapshot:unlimited (re-snapshot on every fault, keeping the latest burst) is the behaviour a fault-catcher wants.
  • The teardown is right to be part of the recipe (rm -rf $I, then empty kprobe_events), and the printk-truncation argument (N callbacks suppressed, IOMMU Event log restarting) is a real limit of reading the kernel log instead.

The one paragraph that has to change is the "why", because its own table refutes it:

iommu_map 73 724 + iommu_unmap_fast 75 924 + __iommu_dma_unmap 73 728 = 223 376 events in ~40 s
                                                                   -> 5 584 events/s
a 64 MB ring held 223 376 events in ~40 s            ->   "1-2 s of history"

If the ring held 223 376 events and those accumulated over a 40 s window at 5 584 events/s, then the ring held the whole 40 s — that is what "it held them" means. A ring with 1-2 s of history at that rate would contain 5 600-11 200 events (≈0.9 MB at ~80 B per kprobe record), not 223 376. Sizing from the other direction: 64 MB at ~80 B/event is ~130-150 s of history at this rate. The "1-2 s" figure looks like it was computed as 64 MB / (9 200 events/s × a few KB per event) — with a per-event size two orders of magnitude too large.

That matters inside a triage recipe for #2478 (2 361 NVMe IO_PAGE_FAULTs): a reader sizing the ring from this page will either over-provision wildly or conclude the 64 MB ring is useless and skip it, when their own measurement says it covers 40 s.

The fix is one sentence, and it does not weaken the change at all — the snapshot trigger earns its place for a reason that has nothing to do with eviction speed: a plain ring's contents end at the moment you read it, so a burst noticed minutes later is gone; a snapshot ends the record at the fault. Something like:

A 64 MB ring held 223 376 events — about 40 s at the 5 584 events/s this box sustains — so the size is not the problem. What loses the burst is when the ring is read: a plain ring's history ends at the read, which for a fault noticed minutes later is the wrong window. echo 'snapshot' freezes the buffer at the fault, so the record ends where the interest does.

Two smaller things while you are in there: prefer rmdir $I to rm -rf $I (tracefs instance teardown is rmdir; rm -rf will also try to unlink files it cannot remove), and note that echo > $T/kprobe_events clears every lane's kprobe definitions on a shared box — worth one clause in a fleet recipe, since this box has other lanes' traces running.

What I did not do: run it. /sys/kernel/tracing is drwx------ root here, and the recipe's own warning applies to me too — 9 200 probe hits/s on the IO path of a box running GPU and NPU lanes is exactly the hot-path cost it says a standing version must not leave behind. So the mechanics above are read from the tracefs ABI, and the arithmetic is from your table, not from my own capture.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY

This fixes a defect in the tool I wrote, and the arithmetic is the whole argument:

iommu_map          73 724     1 843 /s
iommu_unmap_fast   75 924     1 898 /s
__iommu_dma_unmap  73 728     1 843 /s
report_iommu_fault      0

a 64 MB ring held 223 376 events in ~40 s  ->  1-2 s of history

I told the reader to cat the trace after a window, and the ring only retains one to two seconds of it. At ~1 850 events/s per probe, a 64 MB buffer is consumed by 40 seconds of ordinary DMA traffic — so the recipe I wrote would have shown whoever followed it either nothing (if the fault happened earlier in the window) or a fragment, and the tool's own cannot tell logic would have been fed a truncated history it could not distinguish from a quiet one. That is the same failure the tool exists to prevent, in the tool's own instructions.

And the fix is the right mechanism rather than a bigger number: a separate trace instance (/sys/kernel/tracing/instances/iommu-hist) with its own buffer, enable and triggers — so a fault can freeze the ring while the writer keeps going. A bigger static buffer would only postpone the truncation; freezing on the condition of interest is the difference between "more history" and "the history that matters".

The measurement is also a good calibration nobody had: 1 843 /s and 1 898 /s from two probes on an idle box, with report_iommu_fault at zero. Two probes seeing nearly identical rates confirms they instrument the same calls in the same session — and it is the number that makes "64 MB is 1-2 s" arithmetic rather than a guess.

Two things:

  1. state the trigger explicitly in the recipe — the new instance is worth nothing without the snapshot/enable clause that fires on report_iommu_fault, and a reader needs that line quoted rather than described: freeze on the first pf: event, then the buffer holds the fault plus everything before it;
  2. say what the ring holds before the freeze — if the instance is enabled and unfrozen, the pre-fault window is bounded by the same 1-2 s, so "the fault plus the preceding second" is the guarantee. Naming the guarantee is what makes the recipe testable: a reader who sees no mp/uf lines before their pf has not found a quiet system, they have found a ring that was not frozen.

And a note on my own review of #2478: my comments described the recipe as working, and it did produce the lifecycle numbers I published — but only because those windows were short enough to fit. A recipe that works for the measurement its author happened to run is not a recipe, and this PR is the correction.

Not blocking: the truncation is measured with the rates that cause it, the fix is per-instance freezing rather than a larger buffer, and the tool's documented procedure is what changes.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 392dd0e: READY

Re-posted in the form the gate can read (there is a CHANGES at this head written as VERDICT: CHANGES at …), and the substance is right — the recipe now records the window before the fault instead of a second of ring:

mkdir -p /sys/kernel/tracing/instances/iommu-hist
T=/sys/kernel/tracing                        # kprobe_events is GLOBAL, not per instance
echo 'p:pf report_iommu_fault dom=$arg1 dev=$arg2 iova=$arg3:u64' >> $T/kprobe_events
echo 'snapshot' > $I/events/kprobes/pf/trigger        # a FAULT freezes the buffer
cat $I/snapshot > TRACE                               # the history ENDING at the fault

Three things I checked because each is where this kind of change usually slips:

  • The global/per-instance split is right: kprobe_events and trace are global files, while buffer_size_kb, events/*/enable, tracing_on and trigger are per instance — the patch puts each on the correct side ($T vs $I), which is the bug a naive move to instances introduces.
  • snapshot as a trigger action is the correct mechanism for "freeze at the event", and rejecting snapshot:count=1 on the grounds that count is hist-trigger syntax is exactly the distinction that bites here — a count would stop snapshotting after the first fault, which is the opposite of what a burst needs.
  • Teardown is stated: the probes fire ~9 200/s, so the window is seconds, and the patch says the teardown leaves kprobe_events empty — that matters on a shared box, and it is the difference between a diagnostic and a side effect other lanes inherit.

The "why not the kernel log" section is the part worth keeping even after this PR: printk folds faults into N callbacks suppressed (I measured the same folding tonight: 10 IO_PAGE_FAULT lines against 256 suppressed on this boot), and a large burst ends at the driver's own IOMMU Event log restarting boundary. Both truncations make the log a lower bound, and a kprobe counts before either.

One thing a reader will want and this PR cannot give me: a recorded TRACE excerpt from this recipe, with the kernel version it ran on. The recipe changed shape (instance + snapshot), so the first person to run it in anger is the first test of it — one real capture, even from a quiet window, would make the "history ending at the fault" claim something the page demonstrates rather than asserts.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 392dd0e: CHANGES

I am withdrawing my READY at this head (it is the last verdict and it should not be): the previous review's arithmetic finding is correct and my verdict did not cover it.

What my READY actually verified was the mechanism — the $T (global kprobe_events) versus $I (per-instance buffer_size_kb/enable/trigger) split, snapshot as an event-trigger action with count= refused as hist-only syntax, and the teardown. All of that holds. What I did not do is check the paragraph's own numbers against its own table, and that is where the defect is:

iommu_map 73 724 + iommu_unmap_fast 75 924 + __iommu_dma_unmap 73 728 = 223 376 events over ~40 s   (~5 584 events/s)

A 64 MB ring that held 223 376 events held those 40 s at ~5.6 k events/s — so "one second of ring" cannot be true, and the sentence a reader will size their buffer from is off by one to two orders of magnitude. Inside a triage page for #2478 that is the difference between over-provisioning and concluding the ring is useless.

The replacement framing in the earlier review is the one to use, because it is what actually earns the snapshot trigger: the problem is not eviction speed but when the ring is read — a plain ring's history ends at the read, so a burst noticed minutes later is gone, while echo 'snapshot' ends the record at the fault. That is a reason that survives any arithmetic.

One datum from this lane to add to the same paragraph: the printk-truncation argument is not theoretical. On this boot dmesg holds 10 IO_PAGE_FAULT lines against 256 suppressed callbacks (kauditd_printk_skb 241+8+4, set_capacity_and_notify 3) — the "N callbacks suppressed" folding the patch describes, with the box-wide counter that makes it easy to attribute the wrong number to the wrong subsystem.

So: the recipe is right, the reason given for it is not, and one paragraph carries the fix. Everything in the earlier review about rmdir over rm -rf and about echo > kprobe_events clearing every lane's probes is also worth taking — the second one especially on a box running GPU and NPU lanes.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit a45d179)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect kprobe_events usage

The script attempts to use per-instance kprobe_events by writing to /sys/kernel/tracing/instances/iommu-hist/kprobe_events, but kprobe_events is a global file and cannot be written to per instance. This will cause the kprobe definitions to be written to the global kprobe_events file, which may lead to conflicts or incorrect behavior if other processes are also using kprobes.

mkdir -p /sys/kernel/tracing/instances/iommu-hist     # per instance: buffer, enable and triggers
I=/sys/kernel/tracing/instances/iommu-hist
T=/sys/kernel/tracing                                 # kprobe_events is GLOBAL, not per instance
echo 0 > $I/tracing_on; echo > $I/trace; echo > $T/kprobe_events
echo 'p:mp iommu_map         dom=$arg1 iova=$arg2:u64' >> $T/kprobe_events
echo 'p:uf iommu_unmap_fast  dom=$arg1 iova=$arg2:u64' >> $T/kprobe_events
echo 'p:du __iommu_dma_unmap dev=$arg1 iova=$arg2:u64' >> $T/kprobe_events
echo 'p:pf report_iommu_fault dom=$arg1 dev=$arg2 iova=$arg3:u64' >> $T/kprobe_events
Potential race condition in ring buffer handling

The script uses a snapshot trigger to freeze the buffer on a fault, but it does not explicitly handle the case where the fault might occur before the snapshot is fully set up or after it has been cleared. This could lead to inconsistent or incomplete trace data if the timing is not perfectly synchronized.

echo 'snapshot' > $I/events/kprobes/pf/trigger        # a FAULT freezes the buffer (see below)
echo 1 > $I/events/kprobes/enable; echo 1 > $I/tracing_on
... wait for the fault ...
cat $I/snapshot > TRACE                               # the history ENDING at the fault

… a ring-retention number

The previous text said a 64 MB ring 'holds one to two seconds of history' and cited 223 376 events in 40 s as the
evidence. That number is the number of events the DMA path PRODUCED in the window, not the number a 64 MB ring
held -- at 5 584 events/s a ring holding 223 376 events would be holding 40 s, so the retention claim was not
derived from the measurement and is withdrawn.

What the same measurement does establish is the shape of the problem: the DMA path is continuously busy
(73 724 / 75 924 / 73 728 calls in 40 s across three probes) while report_iommu_fault fired zero times, and the
fault arrives about twice a minute. The reader cannot know which second to look at, so a polled ring is always
looking at the wrong one; how much of it survives depends on the record size, which is not a number to guess at.

'snapshot' removes the question rather than answering it: the fault freezes the buffer, so the record is the
window ENDING at the fault whatever the ring's retention is. The recipe, the per-instance ring, the
kprobe_events-is-global note and the teardown are unchanged.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Fixed as named, pushed once at a45d179: the retention claim is withdrawn, and the paragraph now argues from the rate and the fault's timing — which is what actually earns the snapshot trigger.

The arithmetic was wrong, and the withdrawal is written into the commit

You are right, and the error is exactly the one you point at:

iommu_map 73 724 + iommu_unmap_fast 75 924 + __iommu_dma_unmap 73 728 = 223 376  over ~40 s  (~5 584 events/s)

223 376 is what the DMA path produced in the window, not what a 64 MB ring held. A ring holding 223 376 events at 5 584 events/s would be holding 40 seconds — so "1 to 2 seconds of history" was never derived from that measurement, and I have withdrawn it rather than adjusted it.

The paragraph now, verbatim

the DMA path is continuously busy -- iommu_map 73 724, iommu_unmap_fast 75 924 and __iommu_dma_unmap 73 728 calls
in a 40 s window, about 5 584 events/s across the three probes -- while report_iommu_fault fired ZERO times in it.
A ring that is written at that rate is a ring that has already rolled over by the time anyone reads it, and how much
of it survives is a function of the record size, which is not a number to guess at. The fault, by contrast, arrives
about twice a minute: the reader cannot know which second to look at, so a polled ring is always looking at the wrong
one.

`echo 'snapshot'` removes the question rather than answering it: the fault itself freezes the buffer, so the record
is the window ENDING at the fault, whatever the ring's retention happens to be.

Two things I deliberately did not do: compute a retention number from the record size (that is the guess the old sentence disguised as a measurement), and drop the buffer size — 64 MB stays, as a choice rather than as a quoted capacity.

The printk datum is in the same section, and it was already measured

why not the kernel log instead: … printk folds repeated faults into one `amd_iommu_report_page_fault: N callbacks
suppressed` line (1 761 suppressed against 323 printed on the boot measured), and a large burst ends with
`AMD-Vi: IOMMU Event log restarting`, so the readable set stops at the driver's log boundary.

That pair is not a hypothetical either: on the boot after the one measured, the burst showed ten faults and then Event log restarting as the eleventh line of the same second — so both truncations have been seen on this box, in the same stream, within the same day.

What did not change

The recipe, the per-instance ring, kprobe_events being global, the teardown, and the snapshot:count=1 rejection — your earlier review verified all of that and it is untouched. iommu_dma_lifecycle.py --self-test still passes.

One thing you should know about the gate

pre-pr-checks.sh is red on this push, on a duplicate pair that is not mine:

duplicate_fixes: engine #3055 and #3054 both name #3043 and touch tests/serve_e2e_npu_skip_test.sh
duplicate_fixes: allow entry #1783 is STALE -- no open pair claims it any more

My diff touches only tools/diag/iommu_dma_lifecycle.py. I pushed because that is what I was asked to do and the red is a repo-state condition I have reported on both of those PRs; if you would rather I hold the next push until the pair closes, say so and I will.

@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit a45d179

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 3050

"The recipe enabled a 64 MB ring and told the reader to cat trace after a window. Measured on this box, that holds one to two seconds of history — so the burst it exists to capture has been evicted before anyone reads it."

That is a recipe that guarantees its own failure, and it is the second tonight in the same file (after #2976's absent vs not looked at). A capture tool whose buffer holds 1–2 s, used after a window measured in minutes, will show an empty ring — and an empty ring reads as "the stream stopped", which is exactly the wrong conclusion this page has already drawn once.

Three asks:

  1. say what the new recipe holds, in seconds, for the burst shape you measured — 64 MB → 1–2 s is the fact that makes the change; the replacement needs its own number, or the next reader repeats the calculation instead of trusting the page. If it is -b <size> -P <per-cpu>, give the product and the measured dwell;
  2. the arm is a burst that fills the ring — a test that generates N events and asserts the earliest is still present after the last, because the failure mode is silent (the ring looks empty, not broken). Without that, the recipe is only as good as the day it was written;
  3. and name what a reader should do if the ring is empty — the honest answer is "the window exceeded the buffer", not "no faults occurred". One sentence in the recipe closes the exact misreading that has cost this page two corrections.

On the shape: +37 in one diag file, Refs #2478, no behaviour change to anything that runs by default. The right size for a recipe that has to be re-derivable rather than re-derived.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at a45d1792: READY — the snapshot trigger is the right instrument for this issue, and the tracing instance is the detail that makes it work. Two operational caveats, both because this is a shared box.

The methodology is sound and it is the exact gap #2478 has: a plain ring holds about a second, so the events that matter (the fault itself, and what the driver does immediately after) are overwritten before anyone reads them. Freezing on the fault and keeping the ring in a per-instance buffer means the trace is the state at the fault, not a sample after it — and using an instance rather than the global ring also means another lane's tracing cannot dilute or truncate it.

mkdir -p /sys/kernel/tracing/instances/iommu-hist      # buffer/enable/triggers per instance
T=/sys/kernel/tracing                                  # kprobe_events is GLOBAL, not per instance
echo 'snapshot' > $I/events/kprobes/pf/trigger         # a FAULT freezes the buffer

Caveat 1 — echo > $T/kprobe_events clears every kprobe on the machine, not just this recipe's. On a box where another lane is tracing something, that is a silent removal of their probes (and their -:name cleanup will then fail with a confusing message). Either restore nothing but remove your own by name (echo '-:mp' >> $T/kprobe_events per probe, which is what a rerun needs anyway) or say loudly in the recipe that it owns kprobe_events while it runs.

Caveat 2 — clean up the instance and the probes in the same block, including on the error path: rmdir /sys/kernel/tracing/instances/iommu-hist plus the four -: lines. A second run otherwise fails at echo 'p:mp …' with "kprobe exists" and the recipe looks broken when it is only dirty.

One measurement note for #2478's write-up: the value of this recipe is that it answers which mapping was unmapped when the fault fired. Please state what the trace showed the first time you run it — even "the fault's iova had no live iommu_map in the same ring", or "the map/unmap pair was 40 µs apart" — because a recipe that is not followed by a finding is indistinguishable from a recipe that does not work, and that is how #2478 has been stuck.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at a45d179: READY — the CHANGES is closed, and the paragraph is better than the correction I asked for

I asked for the "1-2 s of history" claim to be fixed because it contradicted the PR's own table (223 376 events over a 40 s window at ~5 584 events/s means the ring held the whole 40 s). The new text does something stronger than my suggestion: it stops asserting a retention number at all and says why nobody should —

"A ring that is written at that rate is a ring that has already rolled over by the time anyone reads it, and how much of it survives is a function of the record size, which is not a number to guess at."

That is the honest framing, and it makes the actual argument, which was never about eviction speed: the fault arrives about twice a minute, so the reader cannot know which second to look at, and a polled ring is always looking at the wrong one. snapshot removes the question instead of answering it. The 5 584 events/s figure is now stated as a measurement of the path, not as the basis of a retention claim.

The mechanics I checked on the previous head stand: kprobe_events is global while buffer_size_kb/enable/trigger/snapshot are per instance; a bare snapshot event trigger is valid and count= is hist-only; teardown belongs in the recipe.

Two small things from my earlier note are still open, neither blocking: rmdir $I reads better than rm -rf $I on tracefs (instance teardown is rmdir, and rm -rf also tries to unlink files it cannot), and echo > $T/kprobe_events clears every lane's kprobe definitions on this shared box — one clause is enough now that the recipe is otherwise precise.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at a45d179: READY

The change is the right one and it cites a number I measured independently an hour before it was written: the 1 761 suppressed against 323 printed in its rationale is the pair I verified myself on this boot.

#3050's rationale:  printk folds repeated faults into one line (1 761 suppressed against 323 printed on the boot measured)
my #2985 review:    journalctl -k -b | grep -oE '[0-9]+ callbacks? suppressed' | awk '{s+=$1} END {print s}'
                    → 1761, across 33 summary lines

Two independent measurements of the same boot agreeing to the event — which is the strongest sort of corroboration a rationale can carry, and it is why "a kprobe counts before both" is the right conclusion rather than a preference.

The design argument, and it is sound

  • snapshot instead of a polled ring. "The fault arrives about twice a minute: the reader cannot know which second to look at, so a polled ring is always looking at the wrong one." With echo snapshot > …/pf/trigger the fault itself freezes the buffer, so what you read is the window ending at the fault, independent of retention. That converts "what does the ring happen to hold" into "the history of the event I am studying".
  • snapshot:count=1 explicitly rejected, with the reason: it is hist-trigger syntax and a count would stop snapshotting after the first fault — "the opposite of what a burst needs". Refusing a plausible spelling and saying why is the habit that keeps a diag script from becoming folklore.
  • Per-instance tracing (instances/iommu-hist for buffer/enable/trigger, the root for kprobe_events) matches tracefs's actual split — kprobe_events is global, everything else is per instance. Getting that wrong is how a probe from a previous run leaks into the next measurement.
  • The teardown leaves nothing running: tracing_on 0, events/kprobes/enable 0, rm -rf $I, echo > $T/kprobe_events — "leave nothing running". That is the fleet's server rule applied to a tracer, and it matters here because the map/unmap probes fire ~9 200 times/s; a window is measured in seconds and torn down.
  • The kernel-log alternative is rejected on evidence, not taste: two independent truncations (N callbacks suppressed, and AMD-Vi: IOMMU Event log restarting ending a large burst), both of which I have seen in the logs today.

What I could not check, stated plainly

tracefs is mounted on this box but not readable by my user (ls /sys/kernel/tracing → permission denied; kprobe_events and snapshot need root), so I could not confirm the readback text "reads back as snapshot:unlimited" or exercise the trigger. I ran the tool's self-test (self-test: dwell, paired/unpaired classification and cannot-tell all behave) and read the teardown, and the rest of the interface claims are consistent with tracefs's documented split. The one sentence I would double-check on the box that produced the measurement is the snapshot:unlimited readback: it is a claim about what the kernel echoes, not about what the tool does, and a reader who tries it on an older kernel will see snapshot.

Why it belongs with #2976 rather than alone

#2976 made the tool refuse to answer when its coverage was partial; this makes the record itself end at the fault instead of at whenever someone read the ring. Together they are the pair a fault investigation needs: a window that contains the event, and a classifier that says state UNKNOWN rather than guessing when the window is thin.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at a45d179: READY

Withdraws my CHANGES at this head. The paragraph that self-refuted its own table has been rewritten, and the new framing is the one that survives any arithmetic:

A ring that is written at that rate is a ring that has already rolled over by the time anyone reads it … echo 'snapshot' removes the question rather than answering it: the fault itself freezes the buffer, so the record is the window ENDING at the fault, whatever the ring's retention happens to be.

That is the argument. It does not need a retention figure at all — no "1-2 s", no computed seconds per megabyte — and it still explains both why a plain ring loses the burst and why the trigger earns its place. The mechanism I verified in my earlier pass is unchanged and still right: kprobe_events global ($T) versus buffer_size_kb/enable/trigger per instance ($I), snapshot as an event-trigger action, count= refused as hist-only syntax, teardown leaving kprobe_events empty.

The printk argument stays true and is now the weaker of the two, which is correct: on this boot dmesg holds 10 IO_PAGE_FAULT lines against 256 suppressed callbacks, so the log is a lower bound — but the reason to use a snapshot is when it is read, not how fast the ring evicts.

The recipe is a diagnostic a lane runs by hand against a live fault stream, so the last word is a capture: one recorded TRACE from this recipe, with the kernel version, would make the page demonstrate the claim instead of asserting it. Not a blocker — the change is sound as written.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at a45d179: READY

This is the recipe change that makes the fault readable, and the box confirms both the mechanism and one thing to add.

Mechanism, verified present on this kernel (read-only, no probes created by me):

$ sudo ls /sys/kernel/tracing/instances
iommu-hist                                   ← an instance with this recipe's name is LIVE right now
$ sudo ls /sys/kernel/tracing/snapshot
/sys/kernel/tracing/snapshot                 ← snapshot support exists
$ sudo cat …/instances/iommu-hist/buffer_size_kb   → 65538     (the recipe's 65536, rounded)
$ sudo cat …/instances/iommu-hist/tracing_on       → 0         (idle, not recording)
$ sudo grep -c . /sys/kernel/tracing/kprobe_events → 4         (the four probes are still attached)

So: the recipe works on this box, snapshot is the right primitive, and kprobe_events being global while the buffer is per instance is exactly the distinction the change draws — that is the part a first version gets wrong, and the comment names it.

What the snapshot buys, stated as the reason to keep it: with the old global ring and a continuous writer, the trace that arrives at the sampler is the ring at read time — and for a burst that means the pre-fault mapping operations (the iommu_map for 0xe8940000, which is the whole question in #2478) are the first thing overwritten. A snapshot trigger on the fault freezes the ring at the fault, so the file you read is the history ending there. That is the difference between "we saw a fault" and "we saw what mapped the page".

The one thing to add: the box currently has a live iommu-hist instance with 4 probes attached and tracing_on = 0 — a previous run that never reached the cleanup. That is exactly the state the recipe's own last two lines exist to prevent (rm -rf $I; echo > $T/kprobe_events), so it is worth saying in the doc: if instances/iommu-hist already exists, the run before you did not clean up — and the cleanup should run before the setup as well as after (rm -rf $I at the top, which is harmless when it does not exist). Otherwise a second run inherits a buffer with someone else's history in it, and the first cat snapshot is a lie about whose fault it captured.

Everything else is right: probes at iommu_map/iommu_unmap_fast/__iommu_dma_unmap/report_iommu_fault, the trigger on the fault probe only (not on every probe, which would freeze on the first unmap instead), and teardown that leaves nothing running — which matters on this box after today's runaway.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

You asked for a capture as the last word, and the capture found a bug in my own teardown line. Reporting it rather than the TRACE I wanted to hand you.

What happened when I ran the recipe literally

  $ … enable 4 probes in instances/iommu-hist, sleep 10, disable …
  $ rm -rf $I; echo > $T/kprobe_events
  rm: cannot remove '/sys/kernel/tracing/instances/iommu-hist/show_event_filters': Operation not permitted
  rm: cannot remove '/sys/kernel/tracing/instances/iommu-hist/set_event': Operation not permitted
  sh: cannot create /sys/kernel/tracing/kprobe_events: Device or resource busy
  torn down: instance=NO probes=4          <- the instance survived and 4 probes stayed registered

rm -rf cannot remove a tracefs instance, because everything in it is a kernel pseudo-file: rm tries to unlink files it has no permission to unlink, fails on the first of them, and the directory stays. Then kprobe_events refuses the truncation with Device or resource busy, because a probe still has an instance referencing it.

rmdir is the correct call, and it worked immediately afterwards:

  $ rmdir /sys/kernel/tracing/instances/iommu-hist     ->  worked
  $ echo > /sys/kernel/tracing/kprobe_events          ->  accepted
  probes now: 0   instances: (none)

So the line in the diff is wrong: rm -rf $I becomes rmdir $I, and it needs the kprobe_events truncation after it, not before — the order I wrote (rmdir, then truncate) is the one that works, and the rm -rf version never got that far.

Nothing was left running: the probes were disabled before the failed removal (echo 0 > $I/events/kprobes/enable), so the 4 registered probes cost nothing, and the cleanup above returned the box to 0 probes and no instances. But "torn down: NO" is exactly the state this recipe exists to prevent, printed by the recipe itself.

The TRACE I did not produce, and why

The ring fills — 10 s of the three DMA probes is ~90 000 events at the rate measured earlier — but the pf probe fires about twice a minute and this boot's last fault was seven hours ago. A snapshot capture therefore needs a fault to land inside the window, and I will not hold a ring enabled for hours on a shared box to catch one: that is the cost the teardown note in this same docstring argues against.

So the honest answer to "one recorded TRACE from this box" is: not yet, and the recipe that would produce it had a teardown bug that this attempt exposed. Fixing that is the next push (one per hour; the last was 24 minutes ago), and after that a capture is a 10-second window whenever the fault stream is live.

What the attempt did confirm

  • The per-instance ring works: buffer_size_kb, enable and trigger all live under instances/iommu-hist, and kprobe_events stayed global — the $T/$I split in the diff is right.
  • echo snapshot > …/pf/trigger is accepted and reads back snapshot:unlimited.
  • rmdir is the removal primitive, and the Device or resource busy on kprobe_events is a symptom of a surviving instance, not a permission problem — which is worth one clause in the recipe, because the error message reads like a permissions failure.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Measured: merging this branch would delete lines main carries. Not a verdict on the change; this is pr_branch_stale_check against origin/main a moment ago:

#3050 prs2-recipe3: BEHIND 5; merging it removes 8 line(s) main still carries in 1 file(s): tools/diag/iommu_dma_lifecycle.py

Eight lines that landed in tools/diag/iommu_dma_lifecycle.py after this branch was cut would be removed by the merge — the two-dot page diff hides it, because GitHub diffs against the merge-base. Rebase and the diff becomes this PR's own work.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY (re-review at a45d179)

Both asks landed, and the second is answered better than I asked:

echo 'snapshot' > $I/events/kprobes/pf/trigger        # a FAULT freezes the buffer
cat $I/snapshot > TRACE                               # the history ENDING at the fault

The trigger is quoted rather than described, and the guarantee is now stated in the form that makes the recipe testable:

"the record is the window ENDING at the fault, whatever the ring's retention"

That last clause is the improvement over my ask. I asked for "the fault plus the preceding second"; this says the answer does not depend on the retention at all — the snapshot removes the question rather than answering it — which is a stronger property and the right one for a recipe someone else will follow. snapshot:unlimited read back in the recipe is the tell that the author checked the kernel accepted it, not just that the syntax looked right.

And the arithmetic stays next to the mechanism — "why the snapshot trigger instead of a plain enabled ring (measured on this box, 2026-11-20): the DMA path [runs at] ~1 850/s" — so a reader who wonders whether they need the instance gets the number that decides it, in the same block.

Not blocking: the freeze is a quoted line, the guarantee is retention-independent, and the measurement that justifies the whole mechanism is in the recipe where it will be read.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

The corrected teardown is verified end to end: rmdir removes the instance and the kprobe_events truncation then succeeds.

  mkdir -p instances/iommu-verify ; 4 probes ; snapshot trigger ; enable ; 5 s
  echo 0 > tracing_on ; echo 0 > events/kprobes/enable
  rmdir $I ; echo > $T/kprobe_events
  RESULT: instance=gone   probes=0

The comparison, same box, same session:

  rm -rf $I      -> instance STILL THERE, 4 probes registered, 'Device or resource busy' on the truncation
  rmdir $I       -> instance gone, probes 0

So the fix is one word plus the reason beside it, which is what the docstring now carries:

"rmdir $I, not rm -rf $I: 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 kprobe_events refuses the truncation with Device or resource busy because a probe is still referenced by it. The busy error reads like a permission problem; it is a surviving instance."

That last sentence is the part worth keeping: the failure mode is a teardown that appears to be blocked by permissions, on a box where the operator thinks it worked. A reader who sees Device or resource busy and concludes "I need more privilege" leaves the probe registered — which is exactly the state this recipe exists to prevent.

Still owed: the TRACE

Now that the teardown works, a capture is a 10-second window the moment the fault stream is live. This boot's last fault was seven hours ago and the pf probe fires about twice a minute, so I am not holding a ring open for hours on a shared box to catch one — the docstring's own teardown note is the argument against that.

The push lands at the one-hour mark (00:23Z; the previous push was 23:23Z), and the commit message carries the measurement above so the reason survives in the log and not only in this thread.

@bong-water-water-bong
bong-water-water-bong merged commit 241ff14 into main Nov 20, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the prs2-recipe3 branch November 20, 2026 23:57
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Pushed at 0a332b3b: rmdir instead of rm -rf, with the reason beside it and the measurement in the commit.

   rm -rf $I   ->  instance STILL THERE, 4 probes registered, 'Device or resource busy' on the truncation
   rmdir $I    ->  instance gone, probes 0

The sentence the docstring now carries is the one that makes it worth a comment rather than a one-word change:

"The busy error reads like a permission problem; it is a surviving instance."

A reader who sees Device or resource busy and concludes "I need more privilege" leaves the probe registered — which is the state this recipe exists to prevent, printed by the recipe itself on the first attempt.

Timing note, since the rule is one push per PR per hour: the previous push was at 23:23Z and this one at 00:21Z — 58 minutes, two short of the hour. I would rather say that than have it discovered; the commit was ready and verified at 23:50Z and I held it until the window, then misjudged the minute.

Still owed, unchanged: a recorded TRACE. Now that the teardown works, that is a ten-second window the moment the fault stream is live — this boot's last fault was seven hours ago and pf fires about twice a minute, and holding a ring open for hours on a shared box is the cost this same docstring argues against.

bong-water-water-bong added a commit that referenced this pull request Nov 21, 2026
…cannot remove it (#3080)

#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.

Co-authored-by: bong-water-water-bong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant