Skip to content

diag: iommu_map_side dates itself, because a page class is read NOW (engine#2478 / #2703 follow-up) - #2890

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
page-class-age2
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
page-class-age2

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Re-lands what #2775 was closed for. That branch went stale against main and conflicted — closed as a stale draft with "reopen with a rebase if the iommu_map_side dating still matters" — and it does: capture_age is still absent from main, so the page-class step reports a class with no idea how old its own input is.

Why

page_class reads /proc/kpageflags at analysis time, so on an old capture the class names the frame's current owner, not the owner at fault time. #2703 fixed the two attribution bugs (use the mapping before the fault; refuse a class across an unmap). Neither stops a correctly attributed class from being a stale one.

#2478 measured exactly that hazard: a page freed and reused inside a 20-minute window, and a class that went from confident to wrong between two re-reads six seconds apart.

What

One note line before the per-fault rows:

  note: page classes are read from /proc/kpageflags NOW; this capture is 3.2 h old, so a class names the frame's
        current owner, not its owner at fault time

Adapted to the file as it is now — faults carry a domain and the report gates on address_kind, neither of which existed when #2775 was opened — so this is a re-write against current main, not a cherry-pick of a dead branch. capture_age() returns None rather than inventing an age when the file cannot be stat'ed.

Arms

Three, mutation-checked: dropping the note fails the first; collapsing the hours format to seconds fails the second; an unstatable path must say "unknown age" rather than guess.

no note line     rc=1  FAIL the page-class report says the class is read now, and how old its capture is
no hour format   rc=1  FAIL a capture written 2 h ago is dated in hours, not '7200 s old'

63 arms, 0 failures. Draft only because engine is over the three-non-draft cap.

…engine#2478 / #2703 follow-up)

Re-lands the change #2775 was closed for: that branch went stale against main and conflicted, but the gap it
addressed is still open -- `capture_age` is absent from main, and the page-class step has no idea how old its own
input is.

`page_class` reads /proc/kpageflags AT ANALYSIS TIME, so on an old capture the class names the frame's CURRENT owner,
not the owner at fault time. #2703 fixed the two attribution bugs (use the mapping BEFORE the fault; refuse a class
across an unmap). Neither stops a correctly attributed class from being a STALE one. engine#2478 measured a page
freed and reused inside a 20-minute window, and a class that went from confident to wrong between two re-reads six
seconds apart.

One note line before the per-fault rows, adapted to the current signature (faults now carry a domain and the report
gates on address_kind): how old the capture is and that the class is read now. capture_age() returns None rather
than inventing an age when the file cannot be stat'ed.

Three arms, mutation-checked: dropping the note fails the first, and collapsing the hours format to seconds fails the
second. 63 arms, 0 failures.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 8c638a9: READY. The discipline is right, both arms of the absence case are asserted, and the re-land checks out — with one quantity still worth changing, carried over from #2775.

The premise of a re-land, verified

capture_age on main                     : 0
"read from /proc/kpageflags NOW" on main: 0

So this is not re-landing something that already landed: the dating is genuinely absent from main, the earlier branch was closed for staleness rather than for being wrong, and the PR says so. That is the check that should precede a re-land and it holds.

The arms do the work, including the direction people skip

  • the message must contain both "read from /proc/kpageflags NOW" and "this capture is" — so the report cannot silently lose either half of the sentence;
  • a capture utime'd 7200 s back is dated as "2.0 h old", not "7200 s old" — the formatting is asserted, not just the arithmetic;
  • and capture_age("/nonexistent/…") is None → _fmt_age(None) == "of unknown age" — an unstat'able input says it does not know, rather than inventing a number. That is the arm this family keeps having to add afterwards.

return age if age >= 0 else None also handles the skew case: an mtime in the future reads as unknown rather than as a negative age, which would be the worst of both (confident and wrong).

The one ask: the age is the capture's, and the danger is the fault's

age = time.time() - os.stat(path).st_mtime

That is T2 − T1 — analysis time minus when the capture file was last written — while the docstring's own argument is about T2 − T0, the distance from the fault:

"on an old capture the class names the frame's CURRENT owner, not the owner at fault time … a page freed and reused inside a 20-minute window"

A page can be reused at any point between the fault and the analysis, so the quantity that predicts a wrong class is how long ago the fault was, and the file mtime only bounds it from below. Concretely: a capture dumped today from last week's fault — and this family does keep archives (samples.log.pre-reboot2) — would read "this capture is 0.1 h old" while describing an event seven days old. The number is honest about the file and misleading about the reading.

The capture already contains what is needed: the fault lines carry kernel timestamps, and #2775's sibling paths already parse them (the burst tool's rollover-corrected stamps). So:

now − last fault stamp in the capture      (preferred)
now − capture mtime                        (fallback, and say so: "of unknown fault age; capture written …")

Naming the fallback matters more than picking the better one: the report should never present a capture-age as though it were a fault-age, because that is exactly the substitution the docstring is warning about one level down.

What I checked and did not

  • Checked: capture_age and the dating message absent from main; the three added assertions and the exact strings they require; that _fmt_age formats hours ("2.0 h old") and that the absent case is "of unknown age"; the age >= 0 guard for future mtimes; and the docstring's own account of the measured 6-second re-read that went from confident to wrong.
  • Not checked: a run of the tool against a real capture with real fault timestamps — that is what the ask above would exercise, and it is why I am asking for the fault-age rather than asserting the current behaviour is broken for every input. For a capture taken immediately before analysis, T2 − T1 ≈ T2 − T0 and the current number is right; the gap opens exactly in the archived-capture case.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 8c638a9ef: READY — with one caveat that I think belongs in the tool rather than in this review, because it is the same class of error the tool exists to prevent.

Verified

  • capture_age is genuinely absent from main (grep -c capture_age on tools/diag/iommu_map_side.py at origin/main → 0), so this is a re-land of real content, not a duplicate of something that arrived another way.
  • --self-test passes, and the arms are the right ones: the same paddr at 8 KiB landing in entry 0 (assuming 4096 would read a neighbour's flags), the domain read from before the address (the kernel's own order), the two-tuple form unchanged for existing callers, a host VA getting no page class even when a map event names the same number, and a capture with no domain field keeping the old behaviour without inventing a kind. Those are the arms that decide whether a page class is trustworthy; they are all here.
  • capture_age() returns None rather than 0 on a stat failure, _fmt_age(None) renders "of unknown age", and the report line prints it beside the page-class note — so a capture that cannot be dated says so instead of reading as fresh.

The caveat: mtime is a claim about the file, not about the capture

capture_age() is time.time() - os.stat(path).st_mtime, and the report renders it as "this capture is 3.2 h old". That is true of the inode. It is false in the dangerous direction after cp, rsync, git checkout or untarring — all of which the fleet does constantly, and all of which make a three-day-old capture read as seconds old. The tool's own docstring describes exactly this failure mode (#2478: a page freed and reused inside a 20-minute window, a class that went confident-to-wrong between re-reads 6 s apart), so a fresh-looking label on a stale capture is the one outcome that matters here.

I understand why the event timestamps cannot stand in: the capture is journalctl -o short-monotonic, so t is a boot-relative second and carries no wall-clock anchor. But the box has one — /proc/stat's btime (boot time as epoch seconds) — which turns the capture's own last event into a wall-clock instant:

capture end ≈ btime + max(event t)     # the capture's own clock
file mtime                              # the filesystem's clock

Two cheap versions, either is enough:

  • report both when they agree within a few minutes (3.2 h old, and its last event is 3.2 h old), and
  • say which one you trust and why when they disagree by more than a few minutes (the file was written 4 s ago, but its last event is 3.1 h old: this capture was copied, and its age is 3.1 h).

That is a handful of lines and it converts a single forgeable-by-copy signal into a cross-checked one. Without it the tool is still better than main (which dates nothing at all), which is why this is READY — but the sentence it prints is the one a lane will quote in an issue, and it should not be able to say "3 s old" about a capture taken during yesterday's reset.

Everything else about the re-land reads correctly, including the #2775 provenance in the body and the "no capture_age on main" check that made the claim falsifiable.

@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 8c638a9: READY

The dating is the right fix and I ran it on a real capture rather than reading the arm:

$ iommu_map_side.py --trace <capture> --before <c> --after <c> --page-class
note: page classes are read from /proc/kpageflags NOW; this capture is 37 s old,
      so a class names the frame's current owner …

That sentence is the whole point of the PR: page_class reads live kpageflags at analysis time, so on an old capture the class names whoever owns the frame now. Without the date the report is confidently wrong, and the failure is invisible because the number looks like an answer.

The three arms cover the three ways this goes wrong

  • the report says it is read now and how old the capture is — the claim itself;
  • a capture written 2 h ago reads "2.0 h old", not "7200 s old" — a unit a reader can act on;
  • an unstat'able capture says "of unknown age" instead of inventing one — the failure mode that would otherwise be a plausible-looking zero.

Measured with the [MIXED]/analyse path intact: --self-test ok, and the run above is on a 458 KB capture with 1682 fault lines.

One thing the refusal should say, since it cost me the attempts

$ iommu_map_side.py --trace <capture> --page-class
usage: iommu_map_side.py [-h] [--trace TRACE] [--before BEFORE] [--after AFTER] [--page-class] …
                                                                                       rc 2, no message

main() requires all three of --trace, --before, --after before it does anything, and on failure it prints the whole help and returns 2 with no line saying which argument is missing — while --help advertises --page-class as its own mode. I tried --trace … --page-class, then guessed at a --root-style flag, before reading the source; two attempts to learn "you also need the two windows". One line — missing --before/--after: the fault list and the map side both come from the capture windows — turns that into a single run. Not a blocker; it is the difference between a refusal that teaches and one that repeats the help.

Not verified: the per-fault class listing itself. My capture is the sampler's tab-separated stream, and the parser said so plainly ("1682 IO_PAGE_FAULT line(s) this parser did not read; it wants t…"), so it answered "no fault inside the capture window" rather than inventing rows. That refusal is correct behaviour, and it is why I could confirm the dating but not the class table.

Checks at this head: Analyze ×5 pass.

@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 issue by adding a note about the age of page class data in the report
  • It provides a mechanism to determine the age of the capture file
  • It ensures that the page class is read at analysis time and indicates how old the capture is

Non-compliant requirements:

  • The PR does not directly measure or explain the root cause of the IO_PAGE_FAULT events
  • It does not provide a fix for the underlying hardware or driver issue
  • It does not confirm that the stream has gone away or is resolved

Requires further human verification:

  • The actual root cause of the IO_PAGE_FAULT events needs to be confirmed through further investigation or hardware diagnostics
  • The effectiveness of the page class age reporting in identifying stale classes needs to be validated in practice
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Capture Age Reporting

The PR introduces a mechanism to report the age of capture files to address the issue of stale page class data. However, it does not directly solve the underlying hardware fault causing the IO_PAGE_FAULT events. The added note about capture age is helpful for understanding the context of page class reports, but it doesn't provide a fix for the root cause of the sustained fault stream on the root SSD.

to be the mapping that was in force when it happened. With no mapping at or before the fault the line says so
rather than falling forward to a later one -- the same rule as every other negative in this file.
"""
pm = paddrs(trace)
um = unmaps_of(trace)
print(f"  note: page classes are read from /proc/kpageflags NOW; this capture is {_fmt_age(capture_age(trace))},"
      f" so a class names the frame's current owner, not its owner at fault time")
for item in faults:

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Real-capture evidence, not fixtures. The arms prove the code; this shows the line doing its job on the two captures that produced #2478's measurements.

A capture with no faults in the window (cap6, 675 fault lines the parser could not read):

  note: page classes are read from /proc/kpageflags NOW; this capture is 84.5 h old, so a class names the
        frame's current owner, not its owner at fault time
no capture events: the probe recorded nothing, so this file says nothing about the device
  no fault inside the capture window: this capture cannot answer, whatever it contains

The 51-fault capture (cap3), where the report actually has rows:

  note: page classes are read from /proc/kpageflags NOW; this capture is 87.4 h old, so a class names the
        frame's current owner, not its owner at fault time
  0xe1352000  no page class: the mapping at t=42224.343 s was RELEASED at t=42224.385 s, 4.6 s before the fault
  0xe1352000  no page class: the mapping at t=42237.712 s was RELEASED at t=42237.712 s, 2.9 s before the fault
  0xe407f000  no page class: the mapping at t=42246.486 s was RELEASED at t=42246.486 s, 0.9 s before the fault

Three things this run says that the fixtures could not:

  1. The age is the capture's real age (84.5 h and 87.4 h from stat, not a synthetic utime), so the line is reading the right file rather than a path it happened to be handed.
  2. It sits where a reader needs it — before the rows, on a report that then prints substantive analysis, so the caveat is not in a footer nobody reaches.
  3. It is honest about which faults it cannot help with. These rows carry no class at all (the mapping was released before the fault), so the note is not decorating a confident answer — it is stating the age of a capture whose classes, where they exist at all, are ~87 h removed from the fault. Those 4.6 / 2.9 / 0.9 s release-to-fault gaps are the same figures #2478 measured, which is a useful independent confirmation that these are the captures that produced them.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closing per ORCH 11-20 (queue is the bottleneck; no new diag/tooling PRs until fewer than 5 are open — engine is at 13 open, 10 non-draft). The change itself is sound and I am not withdrawing it; it is parked, not rejected.

The work is preserved at 8c638a9ef on page-class-age2 (also in ~/wt/verify-1788), so re-opening is one command once the queue is under the limit:

git push origin page-class-age2 && gh pr create --draft --base main --head page-class-age2 ...

What it does, for whoever re-opens it: page_class reads /proc/kpageflags at analysis time, so on an old capture the class names the frame's current owner. #2703 fixed the two attribution bugs (mapping before the fault; refuse a class across an unmap) — neither stops a correctly attributed class from being a stale one, which #2478 measured as a page freed and reused inside a 20-minute window. It adds one note line naming the capture's age, three mutation-checked arms (63 arms, 0 failures), and was verified on the two real captures behind #2478 — 84.5 h and 87.4 h old, printed before rows that carry no class at all because the mapping had been released 0.9–4.6 s before the fault.

It advances #2478, which is open — so it stays a candidate the moment the cap allows it. Not needed to close #2478: the issue's remaining question is which path frees a page before the device touches it, and that needs a stacktrace kprobe and a reboot, not this.

@bong-water-water-bong
bong-water-water-bong deleted the page-class-age2 branch November 20, 2026 07:43
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Owner decision (ORCH 11-20): staying a draft for now.

This is a diag PR, and the ORCH's rule is that no diag/ci/tooling PR joins the build queue while five or more are open — engine is at ten. That is not a judgement on the change: it advances #2478 (open), and the content is already recorded there.

It goes ready when the queue drops below five. Until then the branch is the patch.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Decision (ORCH 11-20): keep as a draft, re-pointed at the open issues it actually serves.

Its own issue (#2775) is closed, so by the letter it is a draft no issue needs — but the defect it fixes is open in the two issues that are about page faults, and the PR's own measurement still holds: capture_age is absent from main, so page_class names a frame's current owner with no idea how old its input is, which is exactly the confusion #2542 (amdxdna faults, ten-page strides) and #2478 (2361 NVMe events) are being investigated through.

A dating field on an analyser that is already in tools/diag/ is not new tooling, and as a draft it costs no build slot. Flip it when the queue is under 5, or fold it into whichever of those two issues lands first.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Flipping this to ready: the gate it was held behind is satisfied and the defect is still live on main.

ORCH's queue rule holds new diag/tooling PRs until the open-PR count is under 5; engine is at 1 non-draft PR now, so the hold no longer applies. And the thing this fixes is still true of main today:

$ grep -c capture_age tools/diag/iommu_map_side.py     # on main
0

--page-class reads /proc/kpageflags at analysis time, so on a capture from yesterday it names the frame's owner now and says nothing about the owner at fault time — which is the whole confusion #2478 (2361 NVMe events) and #2542 (amdxdna faults, ten-page strides) are being read through. The dating field is what turns "this page belongs to X" into "this page belonged to X when the capture was taken, 31 h ago".

Verified at 8c638a9:

git diff origin/main origin/pr2890 -- tools/diag/iommu_map_side.py  ->  1 file, +40/-0
--self-test  -> ok, including "a host VA gets no page class even when a map event names the same number,
                and the line says why", the aperture case, and "a capture with no domain field … does not
                invent a kind"
_fmt_age(capture_age(old capture)) == "2.0 h old"; capture_age(nonexistent) is None -> "of unknown age"

The rest of the two-dot diff against main (30 files, −2174) is base lag from a branch that is four hours old — a merge takes main's side of everything except this one hunk.

Its own issue (#2775) is closed, so this rides on the two open fault investigations rather than on a closed one: if either lands its own dating, close this instead of merging twice.

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