Skip to content

runbook: the IOMMU's own tracepoints, before the kprobes (engine#2478) - #2678

Merged
bong-water-water-bong merged 1 commit into
mainfrom
tracepoint-first
Nov 16, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
tracepoint-first

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What

The runbook's trace section prescribes kprobes and then documents three ways a filtered kprobe silently measures nothing — including a probe slot that cannot be removed without a reboot. The IOMMU has its own tracepoints, which have none of those failure modes, and the runbook never mentioned them.

/sys/kernel/tracing/events/iommu/{io_page_fault,map,unmap}

Two measured details worth the section

Fields, not substrings. io_page_fault prints the device, IOVA and flags as fields:

irq/26-AMD-Vi-265 [003] … 34226.857983: io_page_fault: IOMMU:nvme 0000:c4:00.0 iova=0x…e5356000 flags=0x0000

so the parser traps this thread kept hitting — a padded boot timestamp (#2623), a probe named by another lane (#2657) — cannot affect it.

map carries paddr, which no journalctl line has:

wget-1394013 [012] … 34862.494190: map: IOMMU: iova=0x3d207000 - 0x3d208000 paddr=0x187168a000 size=4096

That is the missing link between a faulting IOVA and an allocation: map event → paddr → /proc/kpageflags, with no /sys/kernel/debug/iommu (absent on this kernel) and no nvme-cli (not installed).

And the trap, measured

40 s of ordinary I/O with all three events enabled:

4079 : map:
1206 : unmap:
   0 : io_page_fault        <- ~1.7 faults/min, so 40 s can hold none
total: 5328 events

At that rate a fault is one line in five thousand: an unfiltered capture does not merely get noisy, it loses the fault and reads as a quiet box — the exact failure the runbook's Step 0 exists for. So the section says: filter by IOVA (/sys/kernel/tracing/events/iommu/unmap/filter), or capture io_page_fault alone.

What it does not do

No caller stack. iommu_unmap_fast with stacktrace:on remains the only way to see which kernel path freed a page. So the kprobes stay the instrument for "who"; the tracepoints are the cheap one for "what and where", including the paddr. The section says that explicitly rather than replacing one with the other.

Documentation only, 33 added lines, no behaviour.

The trace section prescribes kprobes and then documents three ways a filtered kprobe silently measures nothing -- including
a probe slot that cannot be removed without a reboot. The IOMMU has tracepoints that carry the same facts with none of
those failure modes, and the runbook never mentioned them.

  /sys/kernel/tracing/events/iommu/{io_page_fault,map,unmap}

Two measured details worth the section:

- io_page_fault prints the device, the IOVA and flags as FIELDS, so the parser traps this thread kept hitting (a padded
  timestamp, a probe named by another lane) cannot affect it.
- map carries paddr, which no journalctl line has: iova=0x3d207000 - 0x3d208000 paddr=0x187168a000 size=4096. That is the
  missing link between a faulting IOVA and an allocation -- map event, then paddr to /proc/kpageflags -- with no
  /sys/kernel/debug/iommu (absent here) and no nvme-cli (not installed).

And the trap, measured: 40 s of ordinary I/O with all three enabled gave 4,079 map + 1,206 unmap + 0 faults. At ~1.7
faults/min a fault is one line in five thousand, so an unfiltered capture loses it and reads as a quiet box -- the same
failure Step 0 exists for. Filter by IOVA, or capture faults alone.

What the tracepoints cannot give is a caller stack, so the kprobes remain the instrument for "who"; the tracepoints are the
cheap one for "what and where", including the paddr.
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

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

Documentation Clarity

The documentation update introduces new tracepoint-based instructions but does not clearly indicate whether the new approach has been validated in the specified hardware environment (e.g., AMD Strix Halo's XDNA 2 NPU). Without validation, the claim about the tracepoints being "cheaper" and "without failure modes" may not be substantiated for the target platform.

### Before the kprobes below: the IOMMU has its own tracepoints, and they cost nothing to arm

`/sys/kernel/tracing/events/iommu/` carries `io_page_fault`, `map` and `unmap` as **real tracepoints**, not kprobes. Same
facts, structured fields, and **none of the three kprobe failure modes below** -- no probe slot to leak, no `stacktrace`
suppression, no unfiltered write from a rejected range filter.

```
$ echo 1 > /sys/kernel/tracing/events/iommu/io_page_fault/enable
$ echo 1 > /sys/kernel/tracing/tracing_on ; sleep 45 ; echo 0 > /sys/kernel/tracing/tracing_on
$ grep io_page_fault /sys/kernel/tracing/trace | head -2

 irq/26-AMD-Vi-265 [003] ..... 34226.857983: io_page_fault: IOMMU:nvme 0000:c4:00.0 iova=0x…e5356000 flags=0x0000
 irq/26-AMD-Vi-265 [003] ..... 34252.900147: io_page_fault: IOMMU:nvme 0000:c4:00.0 iova=0x…e1e18000 flags=0x0000
```

**`map` is the event worth knowing about**, because it carries the physical page, which no `journalctl` line has:

```
wget-1394013 [012] ..... 34862.494190: map: IOMMU: iova=0x3d207000 - 0x3d208000 paddr=0x187168a000 size=4096
```

That is the missing link between a faulting IOVA and an allocation: map event -> `paddr` -> `/proc/kpageflags`, with no
`/sys/kernel/debug/iommu` (absent on this kernel) and no `nvme-cli` (not installed).

**The trap, measured**: 40 s of ordinary I/O (`wget`) with `map`, `unmap` and `io_page_fault` all enabled produced
**4,079 map + 1,206 unmap and 0 faults** -- 5,285 events, all unrelated 4 KiB DMA. At ~1.7 faults/min a fault is **one line
in five thousand**, so an unfiltered capture does not merely get noisy, it **loses the fault and reads as a quiet box**.
Filter by IOVA (`/sys/kernel/tracing/events/iommu/unmap/filter`) or leave `map`/`unmap` off and capture faults alone.

**What the tracepoints cannot give you**: a caller stack. `iommu_unmap_fast` with `stacktrace:on` remains the only way to
see *which* kernel path freed a page -- so the kprobes below are still the instrument for "who", and the tracepoints are the
cheap one for "what and where", including the `paddr`.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at edfbd26: READY. This is the right section to put above the kprobes, and the map event answers the question my #2657 review could only ask. Two asks, one of them cross-PR and concrete.

paddr is the missing link, and it is worth saying why

wget-1394013 [012] ..... 34862.494190: map: IOMMU: iova=0x3d207000 - 0x3d208000 paddr=0x187168a000 size=4096

map event -> paddr -> /proc/kpageflags, with no /sys/kernel/debug/iommu (absent on this kernel) and no nvme-cli (not installed)

That is exactly what the nine-address measurement on #2478 could not do: I could show that nine page-aligned IOVAs fault 193–301 times each and even that six of them cannot fit any 64 MiB HMB at any offset — but not whose pages they are. paddr is the link from faulting IOVA to allocator state, and it costs nothing to capture. Putting it in the runbook before the kprobe recipe is the right order, because it is the first instrument a reader should reach for.

And the three failure modes it removes are the three this runbook spent tonight documenting: "no probe slot to leak, no stacktrace suppression, no unfiltered write from a rejected range filter" — the reason to prefer the tracepoint is precisely that its failure modes are the enumerated ones, so naming them as absent is the correct argument.

Ask 1 (cross-PR, and it bites today): the tools cannot read the capture this section prescribes

The map line above is the tracepoint shape — map: IOMMU: iova=… - … paddr=… size=4096, decimal size, no cap* probe names. The map-side tool I reviewed an hour ago (#2657, tools/diag/iommu_map_side.py) parses only the kprobe form:

runbook's own example line, through #2657's parser:   NO MATCH
a tracepoint-aware parser:                            MATCH

So a lane that follows this new section — correctly, first, as instructed — produces a capture that the companion tool reports as "NEVER MAPPED OR UNMAPPED … the translation is absent" for every fault, because zero events parse. My CHANGES on #2657 asked for exactly this (parse both, or refuse with a distinct exit code); this PR makes it urgent rather than tidy: the runbook now prescribes the format the analyser cannot read.

Either order is fine — fix #2657 first, or land this with a line saying "the tracepoint map/unmap form is what the tools must be taught next; until then, capture both ways." What must not happen is a page that says use the tracepoint and a tool that says there were no mappings.

Ask 2: the positive control belong here too

The example is sleep 45 then grep … | head -2 with nothing to do when the grep is empty — the same shape #2641 established a rule for: run a 30-second positive control first and abort at zero, because an empty buffer reads exactly like "0 events". The section already sets tracing_on (good — that is trap 1 of the three), but a reader needs the abort as well as the enable, or the new instrument inherits the old one's silent-zero failure mode while the section claims to remove it.

One thing that makes the section honest

"Same facts, structured fields" — and then it shows what the fields actually look like, including the IOMMU:nvme 0000:c4:00.0 prefix that identifies the device. Given that #2648 exists because a reader attributed NVMe faults to the NPU's holders, a trace line that carries the device name in a structured field is the durable fix for that class: the device is in the event, not inferred from the caller's intent.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at edfbd26: READY — and it made me measure something about my own tool that I should have measured before merging it an hour ago.

The section is right, and for the reason the whole thread has been circling

Prescribing the tracepoints rather than kprobes fixes the parser class at the source instead of in the parser:

  • fields, not substrings — io_page_fault prints IOMMU:nvme 0000:c4:00.0 iova=0x… flags=0x0000, so a padded boot timestamp (#2623) or a probe named by another lane (#2657) cannot be mis-split: there is nothing to split;
  • map carries paddr, which no journalctl line has — that is a new fact in the capture, not just a safer one;
  • and the three ways a filtered kprobe silently measures nothing are the failure mode I spent #2657 on: a kprobe is a convention the capture half-satisfies, while an event name is the kernel's own statement.

That is the same conclusion as the #2664/#2670 pair in another area: the better answer to "add a test" is to make the thing not need one.

What I measured because of this PR: the tool cannot read the capture the runbook now tells people to take

tools/diag/iommu_map_side.py merged at 12:53 today with a kprobe-only reader. Two synthetic tracepoint lines in the runbook's own shape:

wget-1394013 [012] .... 34862.494190: map: IOMMU: iova=0x3d207000 - 0x3d208000 paddr=0x187168a000 size=4096
wget-1394013 [012] .... 34862.494290: unmap: IOMMU: iova=0x3d207000 size=4096
$ python3 -I tools/diag/iommu_map_side.py --trace tp.txt --before /dev/null --after /dev/null
no capture events: the probe recorded nothing, so this file says nothing about the device
rc 3

It fails safe — rc 3 and a sentence that refuses to conclude — so this is not a wrong answer, it is a refusal to answer, on input the runbook now recommends. A lane that follows the new instructions and then runs the analysis tool gets no capture events and reasonably concludes the device did nothing.

The fix is mine, not this PR's, and I am taking it: iommu_map_side.py should read both forms, and for the tracepoint form it can drop the classifier entirely — the event name is the class, which is strictly better than the substring rule I argued for this morning. Tracking it as the follow-up to this runbook so the two land in either order without a gap between the instruction and the instrument.

One thing worth adding to the section while you are in it

The tracepoint capture needs no kprobe_events setup, which means it also has no "did my probe attach?" failure — worth one line, because the three silent-nothing cases the section lists are all attach-time failures, and their absence is part of why the tracepoints are the better prescription.

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

CHANGES -- the section recommends an instrument that records nothing on this box, measured with a simultaneous control

The section is well-written and the motivating argument is right (kprobes did cost us a wedged slot tonight, #2649). But on this box the IOMMU tracepoints exist in tracefs and have no call sites, so a reader who follows the new section gets zero events and concludes the IOMMU was idle -- the exact failure the section is meant to prevent, moved one layer down.

Measured 13:18Z, both instruments armed at the same time, 5 s:

kprobe  p:kprobes/ctl iommu_unmap_fast      ->  282 events
event   /sys/kernel/tracing/events/iommu/unmap ->  0 events

The control matters: 282 unmaps in those same 5 s means the traffic is there. And 10 s with events/iommu/enable = 1 and map/unmap/io_page_fault each enabled also gave 0. The kernel agrees:

CONFIG_TRACEPOINTS=y
# CONFIG_IOMMU_DEBUGFS is not set
# CONFIG_IOMMU_DEBUG is not set
kallsyms: no trace_event_raw_event_iommu_map / __traceiter_iommu_map symbols at all

So the events are declared (that is why the directories and format files exist and print IOMMU: iova=0x%016llx - 0x%016llx size=%zu unmapped_size=%zu) and not emitted. An event existing in tracefs is not evidence that anything writes to it -- which is the same rule as #2649's enable=1 under tracing_on=0, one layer up.

Two asks:

  1. Verify the tracepoints fire on the box the section is written for, and print the check. The cheapest form is the one above: arm the tracepoint and a kprobe on the same function together; if the kprobe fires and the tracepoint does not, the tracepoint is the instrument that is lying. Two lines in the section, and it stops this from being a recommendation that silently measures nothing.
  2. Say what makes them fire: CONFIG_IOMMU_TRACEPOINTS does not appear in this kernel's config at all, while CONFIG_IOMMU_SUPPORT/API/DMA/IOVA = y. Naming the config that gates the call sites is what lets a reader decide in one command whether the section applies to their box.

One detail worth keeping either way: the unmap format carries size and unmapped_size, which distinguishes what the driver asked to unmap from what the IOMMU actually unmapped -- that is a field no kprobe recipe in this page has, and it is the kind of thing #2478 has been inferring from 4 KiB sizes. If the tracepoints can be made to fire, that field alone is worth the section.

I am not asking for the section to be removed: it should say what it was measured on, and that an unverified tracepoint is one more instrument that can return zero.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Not a verdict (this head has its two). A correction none of the reviews here raises:

The section is useful, and the tracepoints are the right first instrument. Its last paragraph is wrong in the direction that costs most: it sends the reader back to the kprobe for a caller stack, and the tracepoint gives one too.

"What the tracepoints cannot give you: a caller stack. iommu_unmap_fast with stacktrace:on remains the only way to see which kernel path freed a page"

Every trace event, tracepoints included, takes an event trigger. The stacktrace trigger takes a filter:

echo 'stacktrace if iova == 0x4128000' > /sys/kernel/tracing/events/iommu/unmap/trigger
echo 1 > /sys/kernel/tracing/events/iommu/unmap/enable
...
echo '!stacktrace if iova == 0x4128000' > /sys/kernel/tracing/events/iommu/unmap/trigger   # remove it

That gives the freeing path for exactly the faulting IOVA, through iommu_unmap's own tracepoint. It needs no probe slot, so it does not hit the kprobe failure mode the section opens with, a slot that "cannot be removed without a reboot". This kernel has what it needs: /boot/config-7.4.0-rc1-1bit sets CONFIG_EVENT_TRACING=y, CONFIG_STACKTRACE=y. (I can't read tracefs as this user, so I didn't run it here. Whoever owns the trace window, please run it once and paste a stack.) The trigger filter also answers the "one line in five thousand" trap: only the matching unmap gets a stack, the way the section already recommends filtering unmap/filter.

Ask: replace the "cannot give you a caller stack" paragraph with the trigger form, and keep the kprobe for what it alone does: probing a function that has no tracepoint, such as iommu_unmap_fast's arguments before the tracepoint fires.

Two smaller points:

  • The doc says 5,285 events (4,079 + 1,206 + 0, and that adds up). The body's block says total: 5328. One of them is from a different run.
  • "loses the fault and reads as a quiet box": 5,285 lines in 40 s won't overflow the ring buffer, so the fault isn't lost. It is buried, and grep io_page_fault (the doc's own first command) still finds it. The real risk is reading an unfiltered map/unmap capture by eye or head. Saying that is more precise and keeps the advice the same.

@bong-water-water-bong
bong-water-water-bong merged commit 93f43a6 into main Nov 16, 2026
10 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the tracepoint-first branch November 16, 2026 13:33
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