Skip to content

diag: iommu_map_side: a faults-only capture is not an empty one - #2691

Merged
bong-water-water-bong merged 1 commit into
mainfrom
os3-faults-only
Nov 16, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
os3-faults-only

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

A capture that holds io_page_fault events and no map/unmap events is a real capture with its map side missing. The tool answered it with the sentence it reserves for a file that recorded nothing:

$ python3 -I tools/diag/iommu_map_side.py --trace ~/.cache/scratch-prs2/tp3/trace.txt --before /dev/null --after …
no capture events: the probe recorded nothing, so this file says nothing about the device
rc 3

That file has 26 io_page_fault lines. The message is false about it, and a lane that enabled only the fault tracepoint would read it as "the device did nothing" — the same shape as #2657's NEVER MAPPED OR UNMAPPED on an unmap-only capture, from the other side.

After

no map or unmap events in this capture: 26 fault(s) recorded, so the fault side is present and the map side is unanswerable
  t=14396.199 iova=0xe1d00000: not in this capture's map side: no map or unmap events were recorded, so whether this iova was ever mapped is not answerable here
rc=4

4 is the one-sided code (already used for an unmap-only capture), so a caller can tell it from 3, which now means genuinely nothing. The faults come back with the missing half named.

How the arms found it

The existing arm

empty, hdr2 = analyse([], [], faults, [], faults)
chk(empty == [] and "says nothing about the device" in hdr2, "an empty capture is refused as evidence …")

started failing after the change, because a capture with faults is no longer empty. That is the arm doing its job rather than being edited to fit: it now uses a truly empty capture (no events of either kind), and three new arms cover the new case —

  • a faults-only capture reports its faults and the header says the fault side is present;
  • every row names the missing half rather than claiming absence;
  • exit_code([], [], faults) == 4 while exit_code([], [], []) == 3.

--self-test: 27 → 30 arms, rc 0. Registered as iommu_map_side_self (CMakeLists.txt:472), so it runs in the gate.

Why this was only found now

#2681 (the tracepoint reader, merged 13:54) tested the tracepoint form on synthetic lines I wrote from the runbook's examples. Every one of them had a map/unmap event. The first look at a real capture — 26 faults, no events — hit the guard above. Synthetic fixtures reproduce the shape you thought of; the capture reproduces the shape someone took.

A capture that holds io_page_fault events and no map/unmap events is a real capture with its map
side missing. The tool answered it with the message it reserves for a file that recorded nothing:

  no capture events: the probe recorded nothing, so this file says nothing about the device   (rc 3)

Measured on ~/.cache/scratch-prs2/tp3/trace.txt (26 io_page_fault lines, no map/unmap events): after
this change,

  no map or unmap events in this capture: 26 fault(s) recorded, so the fault side is present and the
  map side is unanswerable
    t=14396.199 iova=0xe1d00000: not in this capture's map side: no map or unmap events were recorded,
                                  so whether this iova was ever mapped is not answerable here
  rc=4

rc 4 is the one-sided code, so a caller can tell it from 3 (nothing captured at all). A lane that
enabled only the fault tracepoint now gets its faults back with the half that is missing named,
instead of a sentence that would send it looking for a device that was fine.

The tool's arms found this the honest way: the existing arm "an empty capture is refused as evidence"
started failing, because with faults present the capture is no longer empty. That arm now uses a
truly empty capture, and three new arms cover the faults-only case (rows present, header says the
fault side is present, every row names the missing half, and rc 4 vs 3).

Self-test: 27 arms -> 30.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at fdbef1a: READY. This is the fourth state the refusal vocabulary needed, and it is separated from the third by both a sentence and an exit code.

The distinction, in three places

no events at all      -> "no capture events: the probe recorded nothing, so this file says nothing about the device"   rc 3
faults, no map/unmap  -> "no map or unmap events in this capture: N fault(s) recorded, so the fault side is present and
                         the map side is unanswerable"                                                                   rc 4
map/unmap present     -> the answer
  • rc 3 vs rc 4 is the part that makes it usable by a script: "the probe recorded nothing" and "the probe recorded the other half" are different failures with different fixes, and the exit code now says which without parsing prose.
  • Every row carries the reason: "not in this capture's map side: no map or unmap events were recorded, so whether this iova was ever mapped is not answerable here". That matters more than the header, because the rows are what get pasted into an issue — and a row that says "cannot answer" is worth more than one that says "never mapped".
  • And it is measured, not imagined: ~/.cache/scratch-prs2/tp3/trace.txt — 26 io_page_fault lines, no map/unmap events — is the capture that produced the wrong sentence, and the arm asserts both the header phrase and every row's wording against that shape rather than a synthetic single line.

Why this was the right thing to catch

The old sentence — "the probe recorded nothing" — is a claim about the instrument, and it was false. A capture with 26 fault events is a <good capture> with a missing half; telling the reader their probe recorded nothing sends them to re-arm a probe that worked. That is the same failure #2648 fixed on the other axis (a fault on another device is not this device's) and #2657 fixed before it (a file the tool cannot parse is not an empty file): the tool's inability, reported as the world's absence. Three PRs, three axes, one rule.

One ask, small

The vocabulary is now 0 answered, 2 usage, 3 nothing recorded, 4 a side absent. That belongs in the module docstring as a four-line list, the way pin_holdings lists its 0/1/2 — because the next caller will want to branch on 4 and will otherwise infer it from the header text, which is how exit codes get re-invented at each call site.

What I owe this thread

#2657 (my first CHANGES), #2681 (tracepoint parsing + refuse-before-render), #2691 (faults-only is not empty): three rounds, and each round removed a way for the tool to be confidently wrong about a file it could not read. The final shape — parse both formats, refuse before speaking, and name which half is missing with its own code — is what I should have asked for in the first review instead of the first deficiency I noticed.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Verdict as an issue comment: the shared identity already holds a pending review on this PR, so POST /reviews returns 422 (the standard header for that case). Content unchanged.

VERDICT: READY -- 4 for one-sided and 3 only for genuinely empty is the right encoding, and the arm pins both

The defect is the third instance of one shape tonight, and it is stated in the terms that make it checkable: a capture with 26 io_page_fault lines was answered with "no capture events: the probe recorded nothing, so this file says nothing about the device" -- "the same shape as #2657's NEVER MAPPED OR UNMAPPED on an unmap-only capture, from the other side." Naming the mirror image is what turns three separate fixes into one rule: an instrument must say which half it looked at, and a capture is only empty if it holds nothing.

The rc split is exactly right: 4 for faults-only (the one-sided code, already used for an unmap-only capture) and 3 reserved for genuinely nothing, pinned by exit_code([], [], faults) == 4 and exit_code([], [], []) == 3. That is the difference between "I could not look" and "there was nothing to look at", which this fleet has now needed in five different tools.

One integration ask, because #2681 merged and this is built on top of it: the faults reach analyse() as (before, after) journal sets, while #2681 added reading io_page_fault from the trace. So the real tracepoint capture -- io_page_fault lines in the trace, /dev/null journals -- has faults == [] and lands back in the "empty" branch unless the two paths are joined. Two things follow:

  1. Feeding trace faults into the same set (deduplicated by (t, iova), since a capture can carry both a tracepoint and a journal line for the same fault) so that a faults-only trace answers with rc 4;
  2. naming the source in the header -- 26 fault(s) from the trace, 0 from the journal -- because a reader comparing two runs needs to know whether the denominator came from the same instrument, and a silent merge of both would double-count the same fault.

Nothing else: updating the existing "empty capture is refused" arm rather than adding a second one beside it is the right move -- the old arm was asserting the very sentence that was false for this file.

@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 fdbef1a: READY

This fixes a case my own capture produced, and the fix is the distinction the whole tool is about: a faults-only capture is not an empty one.

The bug, from my data

The comment cites ~/.cache/scratch-prs2/tp3/trace.txt — 26 io_page_fault lines and no map/unmap events, because I had armed only the fault tracepoint for that window. The tool read it as:

no capture events … says nothing about the device      rc 3

which is wrong twice: the capture did contain 26 faults, and 3 means "nothing captured at all" — a claim about the probe that this capture does not support. A capture with one side present is a capture with a side absent, which is 4, and the tool already uses 4 for exactly that.

def exit_code(maps, unmaps, faults=()):
    if not maps and not unmaps:
        return 3 if not faults else 4      # 3 = nothing at all; 4 = a side is absent

The arms

ok   a faults-only capture reports its faults, not 'the probe recorded nothing': … 2 fault(s) …
ok   faults-only exits 4 (a side is absent); truly nothing exits 3

and the per-fault rows say map side … not answerable rather than implying the page was never mapped.

Mutant — collapse the two cases back:

return 3      # faults-only reads as nothing captured
FAIL faults-only exits 4 (a side is absent); truly nothing exits 3

One arm, by name, and it is the arm that distinguishes two exit codes that a reader would otherwise conflate.

Why this is the same defect class the tool has been fixing all day

#2657 → #2681 → #2691 is one thread: "an empty result is not a negative", then "a comment is not a wiring", then "a fault count is not an absence of a capture". Each head removes one way for the instrument to answer a question it was not asked, and this one is the cheapest of the three — two lines and two arms — because the exit code already existed. The fault side is the one this tool can always report: it comes from the journal, not from a probe, so a capture with no map/unmap events and 26 faults is evidence about the device and should never be described as nothing.

@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 fdbef1a: READY

I ran it on the capture the description names, before and after, and the difference is the whole point: main parsed none of the faults and reported a fact about the file that was false.

The before/after on ~/.cache/scratch-prs2/tp3/trace.txt

A tracepoint capture (26 io_page_fault: events, no map/unmap probe at all):

main:   no fault inside the capture window: this capture cannot answer, whatever it contains
head:   no map or unmap events in this capture: 26 fault(s) recorded, so the fault side is present and the
        map side is unanswerable

and the row count matches the file exactly — 26 rows for 26 fault lines. So the old message was not a harmless "cannot answer": it claimed no fault was in the window when 26 were, which is the same shape as the counts this stream keeps correcting (silence reported as a fact).

The new row is the right sentence per fault: "not in this capture's map side: no map or unmap events were recorded, so whether this iova was ever mapped is not answerable here" — it names what is missing rather than implying the page was never mapped.

The arm that was lying, and the split that fixes it

-        empty, hdr2 = analyse([], [], faults, [], faults)      # "empty" with faults present
+        empty, hdr2 = analyse([], [], [], [], [])              # truly empty
+        fo, hdr_fo = analyse([], [], faults, [], faults)       # faults only: not empty

The old "an empty capture must not read as the device is fine" arm passed faults as both the fault list and the after-list, so it was asserting something about an empty capture while holding a non-empty one. Splitting it is what makes both arms true — and it is the same fixture-lies-to-itself pattern as #2688's branch() comment.

The chk(len(fo) == len(faults) and "the fault side is present" in hdr_fo, …) asserts the count and the words, so a header that says the right thing about the wrong number still fails.

One thing worth stating in the docstring, not changed here

The capture that found this is a tracepoint capture, while the tool's own recipe instruments iommu_map/iommu_unmap_fast with kprobes. A fault-only tracepoint capture can never have a map side, by construction — so the new message will be the permanent answer for that whole class, and saying so ("a tracepoint-only capture has no map probe; record the kprobes too if you want the map side") would stop the next reader looking for a bug in the parser.

Not verified: a capture that has both sides but a zero-length map window; the self-test's unmap-only arm covers the adjacent case.

@bong-water-water-bong
bong-water-water-bong merged commit 3e591b1 into main Nov 16, 2026
9 of 10 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the os3-faults-only branch November 16, 2026 15:16
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

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

Incorrect exit code for faults-only captures

The change introduces a new exit code 4 for captures with only fault events, which correctly distinguishes them from truly empty captures that return 3. However, the logic in exit_code function needs to be carefully reviewed to ensure that it properly handles all combinations of map, unmap, and fault events to avoid misclassification.

def exit_code(maps, unmaps, faults=()):
    """0 both sides probed; 3 nothing captured at all; 4 a side is absent, so the missing half cannot be claimed."""
    if not maps and not unmaps:
        return 3 if not faults else 4
    if not maps or not unmaps:
        return 4
    return 0
Header message clarity for faults-only captures

The header message for faults-only captures has been updated to clarify that the fault side is present and the map side is unanswerable. This is a good improvement for clarity, but the message should be verified to ensure it accurately reflects the behavior and is consistent with the tool's intended semantics.

return ([(t, iova, "not in this capture's map side: no map or unmap events were recorded, so whether this "
                    "iova was ever mapped is not answerable here") for t, iova in faults],
        "no map or unmap events in this capture: %d fault(s) recorded, so the fault side is present and "
        "the map side is unanswerable" % len(faults))

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