Skip to content

diag: unmap_fault_order reads the iommu tracepoints, and a format it does not know says so - #2635

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-prs2/tracepoint-unmap
Nov 16, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-prs2/tracepoint-unmap

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

The kernel has two ways to capture an unmap, and this tool knew one.

kprobe      unm: (iommu_unmap_fast+0x4/0x10) iova=0x35540000 size=0x40000     ← a format string a lane writes
tracepoint  unmap: IOMMU: iova=0x00000000e4240000 - 0x00000000e4241000 size=4096   ← events/iommu/unmap

tools/diag/unmap_fault_order.py matched unm:.*iova= only, so a tracepoint capture parsed as nothing — and the tool then printed

unmap_fault_order: no unmap events in the trace -- an empty capture is not a negative; was the probe armed before
the load, and did it fire?

blaming the probe for a parser miss. Measured on engine#2478 with a real events/iommu/unmap capture: the probe was fine, the capture was fine.

That matters because the tracepoint is the better instrument: the fault arrives as a tracepoint too (iommu:io_page_fault, with the device name), so both sides land in one trace with microsecond ordering — and neither goes through printk, so the fault count is not ratelimited.

What changes

  1. TP_UNMAP_RE parses unmap: IOMMU: iova=0x%016llx - 0x… size=%zu beside the kprobe shape. Both are tried per line, kprobe first so existing captures behave exactly as before.
  2. A non-empty capture that matches neither now says so:
unmap_fault_order: 3 line(s) in the trace and none of them is an unmap in either known shape
(kprobe `unm: ... iova=` or tracepoint `unmap: IOMMU: iova=...`): this is a parser miss, not an empty
capture -- show --self-test the line you have

"empty capture" is kept for a file that really has no lines (a lone # tracer: header still counts as empty), so the two situations stay distinguishable — the same distinction the rest of this directory draws between NO SAMPLE and NOTHING HELD.

Arms

ok   a tracepoint unmap line parses (iova, size)
ok   ... and the kprobe shape still parses beside it

Mutation (tracepoint branch removed) fails the first by name. --self-test → 11 arms, 0 failures; scripts/pre-pr-checks.sh → all 11 checks green.

End to end, on a tracepoint capture

$ unmap_fault_order.py --trace tp.trace --journal j.txt
unmap events parsed: 1 over 1 distinct iova(s)
faults parsed: 1; with an unmap of the same iova within +-5000 us: 1
  iova 0xe4240000 size 0x1000: unmap -31 us, unmap BEFORE fault (translation gone)

Note for the merger: #2622 and #2625 also touch this file, so whichever lands second rebases. This diff is one regex, one elif, one branch in parse_trace() and two arms.

Refs #2478, #2542

…does not know says so

The tool knew one capture shape -- a kprobe with a hand-written format string
(`unm: ... iova=0x...`) -- and the kernel has two: `events/iommu/unmap` writes
`unmap: IOMMU: iova=0x%016llx - 0x... size=%zu`, which is the better instrument
(not ratelimited, both sides in one trace, us ordering) and parsed as nothing.

Measured on engine#2478: a tracepoint capture of a real unmap fed to the tool
printed "no unmap events in the trace -- was the probe armed?" -- blaming the
probe for a parser miss, which sends the reader to the wrong place.

Both shapes now parse. And when a non-empty capture matches neither, the message
names the two shapes and says PARSER miss, keeping "empty capture" for a file
that really has no lines.

Arms: a tracepoint line parses (iova, size); the kprobe shape still parses beside
it. Mutation (tracepoint branch removed) fails the first by name.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2635

"The kernel has two ways to capture an unmap, and this tool knew one" — that is the whole class this file keeps producing, and the two-line sample is what makes it concrete:

kprobe      unm: (iommu_unmap_fast+0x4/0x10) iova=0x35540000 size=0x4000

Three asks:

  1. the parser must refuse a line it half-matches — if a tracepoint line parses into a plausible iova but a missing size (or vice versa), the honest outcome is "unparseable, counted", not a partial record. That is diag: unmap_fault_order reads the kernel's PADDED boot stamp, so a real capture can correlate #2622/diag: pin the padded kernel stamp and the human-readable capture form #2623's rule arriving at a second line format, and it is the one that keeps a mixed log from producing a silently-thinned correlation;
  2. say whether the two forms ever appear in the same capture — if a boot can log both (different kernel config, or both probes armed), then the tool must handle them in one run, and the ordering between a kprobe unmap and a tracepoint unmap matters for correlate(). If they are mutually exclusive per boot, say that instead, because it changes the test's shape;
  3. the fixture should be one real line of each form, per diag: pin the padded kernel stamp and the human-readable capture form #2623 — a hand-written tracepoint line is a second definition of a format the kernel owns.

And one thing worth keeping: this is now the third increment on the same reader (#2622 BOOT_RE, #2623 fixtures, this), and each one has been found by running it against real data. That is the strongest possible argument for the rule I put in my last three reviews: keep one live-log case in the suite, because the log is the specification and it keeps changing.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at ffdb75a: READY. This closes the thread #2592 opened and I withdrew: the tool no longer reports a parser miss as a finding about the probe. The two shapes are parsed with their own number bases, and the arms pin that rather than leaving it to a comment.

The base difference is the trap, and the arms catch it

kprobe      unm: (iommu_unmap_fast+0x4/0x10) iova=0x35540000 size=0x40000      -> hex
tracepoint  unmap: IOMMU: iova=0x00000000e4240000 - …1000 size=4096            -> decimal

size=0x40000 and size=4096 are the same kind of field in two encodings, so the natural "one parser for both" refactor gets one of them wrong by a factor of 16ⁿ — and a wrong size is invisible, because the tool only orders unmaps against faults. Keeping int(mu.group(2), 16) on the kprobe path and int(mt.group(2)) on the tracepoint path is right, and the pair of arms is what holds it:

chk(parse_trace(["…unmap: IOMMU: iova=0x00000000e4240000 - 0x00000000e4241000 size=4096 …"])
    == [(100.5, 0xE4240000, 4096)], …)                       <- decimal
chk(parse_trace(["…unm: (iommu_unmap_fast+0x4) iova=0x35540000 size=0x40000"])
    == [(100.0, 0x35540000, 0x40000)], …)                    <- hex, still

Exact tuples, both shapes, in one self-test: unifying the parsing fails one of the two, which is the only thing that makes the distinction durable.

The refusal now knows which mistake it is

239:  {n_lines} line(s) in the trace and none of them is an unmap in either known shape …: this is a parser miss,
      not an empty capture -- show --self-test the line you have      -> rc 3
243:  no unmap events in the trace -- an empty capture is not a negative; was the probe armed …  -> rc 3

That distinction is the whole finding of #2592: the tool blamed the probe for its own blindness, and a lane that followed its advice armed a kprobe that was already firing. Saying "this is a parser miss, show the line" is the difference between a dead end and a five-second fix.

Two notes, neither blocking

  1. Both refusals return 3, so rc alone cannot tell "parser miss" from "genuine empty capture" — only stderr can. If anything ever branches on this, distinct codes (3 / 4) would make the branch possible; today the messages are clear enough that I would not hold the PR for it, but the codes are free now and cost a migration later.
  2. if n_lines > 1 assumes the first line is a header. The comment says so, and for events/iommu/unmap captures it is true. If a capture can arrive with no header — a hand-cut excerpt, a greped file — then a single mangled line falls through to "was the probe armed?", which is the wrong advice again, just for a file of one line. Naming the header (skip a leading # line, then > 0) makes the count independent of a convention nothing enforces.

Why this one matters more than the diff size says

Three tools tonight failed in the same direction: #2624's gap rows were read as a holder, #2627 measured distance without a sign, and this one parsed one of two real capture formats. All three were instruments that answered confidently about data they had not understood. This PR is the one that makes the instrument state its own ignorance — "none of them is an unmap in either known shape" — and that is the property worth having in every diag tool before the next fault storm needs them.

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

The second capture shape is the substance here: a tracepoint capture (events/iommu/unmap) carries the same iova and size as a kprobe one, and a reader that only knew the kprobe format reported "no unmap events" on it — blaming the probe rather than the reader.

Verified end to end on this box with a padded fault and a tracepoint unmap 31 µs earlier:

   bash-1 [002] .... 321.308000: unmap: IOMMU: iova=0x00000000e4240000 - 0x00000000e4241000 size=4096
[  321.308031] h kernel: nvme 0000:c4:00.0: AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0015 address=0xe4240000]

faults parsed: 1; with an unmap of the same iova within +-5000 us: 1
iova 0xe4240000 size 0x1000: unmap -31 us, unmap BEFORE fault (translation gone)

Mutation — the tracepoint branch disabled (mt = None):

rc=1 (1 failure) — the tracepoint shape no longer parses

Restored, --self-test green, including the padded-stamp arm from #2622.

Two details that make the parsing trustworthy: the tracepoint's iova is printed zero-padded to 16 hex digits (0x00000000e4240000) and the same value comes out as 0xe4240000 after int(..., 16) — so it joins against a fault address rather than missing on width; and the tracepoint gives a range (iova - iova+0x1000) whose end is parsed but the size taken from the size= field, with 0x1000 as the fallback when the field is absent. size=4096 is decimal in that shape and size=0x40000 is hex in the kprobe one — the two parsers handle their own base, which is the kind of thing that silently divides a size by 16 if a single parser is reused.

Suggested arm, cheap: one assertion that the decimal size= and the hex size= produce the same byte count for the same page (4096 vs 0x1000). It would pin the base difference between the two shapes, which is the one place a future refactor could unify them wrongly.

Not verified: a real tracepoint capture (needs events/iommu/unmap armed during a fault — no device window taken for a review).

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2478 - Partially compliant

Compliant requirements:

  • The PR addresses the parser issue for tracepoint unmap events
  • It correctly handles both kprobe and tracepoint formats for unmap events
  • It provides better diagnostics by distinguishing between empty captures and parser misses

Non-compliant requirements:

  • The PR does not directly fix the underlying hardware or driver issue causing the IO_PAGE_FAULT events
  • The PR does not provide a solution for the NVMe timeout or reset errors

Requires further human verification:

  • The actual hardware fault conditions described in the ticket need to be verified through further testing or logs
  • The fix should be validated on the actual hardware to confirm it resolves the misdiagnosis issue

2542 - Partially compliant

Compliant requirements:

  • The PR correctly parses both kprobe and tracepoint unmap formats
  • It improves diagnostic accuracy for unmap/fault correlation
  • It provides better error messages when tracepoint captures are not recognized

Non-compliant requirements:

  • The PR does not directly fix the underlying NPU driver issue causing the IO_PAGE_FAULT events
  • The PR does not address the "Unsupported op 18" issue mentioned in the ticket

Requires further human verification:

  • The actual NPU workload that triggers the IO_PAGE_FAULT events needs to be reproduced and tested
  • The fix should be validated with the specific workload mentioned in the ticket (serving ~/models/q4nx-flm35-b8)
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Parser Miss Handling

The tool previously reported "no unmap events" when encountering tracepoint captures, incorrectly blaming the probe. The fix now distinguishes between truly empty captures and parser misses, providing more accurate diagnostics when tracepoint unmap events are present but not recognized by the old parser.

if not unmaps:
    # "no unmap events" covers two different situations and only one of them is about the probe. A capture with
    # lines that match neither known shape is a PARSER miss, and telling the reader to check their probe sends
    # them to the wrong place (engine#2478: a tracepoint capture was reported as "was the probe armed?").
    try:
        n_lines = sum(1 for _ in read_lines(args.trace))
    except OSError:
        n_lines = 0
    if n_lines > 1:   # a header line alone is a genuinely empty capture
        print(f"unmap_fault_order: {n_lines} line(s) in the trace and none of them is an unmap in either known "
              "shape (kprobe `unm: ... iova=` or tracepoint `unmap: IOMMU: iova=...`): this is a parser miss, "
              "not an empty capture -- show --self-test the line you have", file=sys.stderr)
        return 3
    print("unmap_fault_order: no unmap events in the trace -- an empty capture is not a negative; was the "
          "probe armed before the load, and did it fire? (see --self-test for the four shapes)", file=sys.stderr)
    return 3
Missing Tracepoint Support

The tool did not recognize the tracepoint format for unmap events, which are the preferred instrumentation method. This caused tracepoint captures to be silently ignored, leading to incorrect diagnostics about probe configuration.

UNMAP_RE = re.compile(r"unm:.*iova=(0x[0-9a-fA-F]+)(?:.*size=(0x[0-9a-fA-F]+))?")
TP_UNMAP_RE = re.compile(r"\bunmap: IOMMU: iova=(0x[0-9a-fA-F]+) .*?size=(\d+)")

@bong-water-water-bong
bong-water-water-bong merged commit 4e6f3f5 into main Nov 16, 2026
10 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-prs2/tracepoint-unmap branch November 16, 2026 06:03
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