Skip to content

diag: iommu_map_side names the page class behind a faulted IOVA, and reads faults from the trace (engine#2478) - #2703

Merged
bong-water-water-bong merged 3 commits into
mainfrom
page-class
Nov 16, 2026
Merged

bong-water-water-bong merged 3 commits into
mainfrom
page-class

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What

Two additions to tools/diag/iommu_map_side.py, both earned by running it on a real 200 MB capture rather than on a fixture.

1. --page-class — the tracepoint's map event carries paddr, which the tool parsed and threw away. The page class behind it is what decided #2478's diagnosis:

    0x7f180000  no map event carried a paddr for it
    0xe3ff5000  paddr=  0x1dd3dea000  pfn=31276522   LRU
    0xebb3b000  paddr=   0x604fbc000  pfn=6311868    COMPOUND_HEAD

An ordinary LRU page means the block layer DMAs into the page cache, not into a slab buffer of its own — a different and more serious shape than a driver-owned bounce buffer, and not something the tool could say before. On this capture the two delay regimes also have different page types (LRU behind a 517 s gap, COMPOUND_HEAD behind a 10 s one), which is a lead I could not have seen from times alone.

/proc/kpageflags needs root; when it cannot be read the report says unavailable (why) — never none. That distinction is the whole failure class this file exists to avoid.

2. Faults from the capture — a tracepoint capture carries its own io_page_fault events, but main() only read faults from --after, so a capture visibly holding five faults answered "no fault inside the capture window: this capture cannot answer". It now falls back to the trace's own events and says so:

note: no faults in --after; using the 5 fault event(s) carried by the trace itself

The bug this found in itself

The fallback assigned faults, and a stray faults = parse_faults(a.after) left over from the original call clobbered it back to zero — so the CLI printed 0 fault(s) while a direct call of the same functions printed 5. End-to-end output caught it; a self-test on the functions alone would not have, because both functions were individually correct.

Verified

$ python3 tools/diag/iommu_map_side.py --self-test
… 21 arms ok
$ sudo python3 tools/diag/iommu_map_side.py --trace cap4/trace.txt --before j.txt --after j.txt --page-class
note: no faults in --after; using the 5 fault event(s) carried by the trace itself
    0x7f180000 …  0xe3ff5000 … LRU  0xebb3b000 … COMPOUND_HEAD
buffered 414.0..1145.1 s (731 s); 403053 map, 389510 unmap; 5 fault(s) in the window
  t=953.381 iova=0xe3ff5000: nearest map -517696958 us (of 99) | nearest unmap -517696819 us (of 99)
  t=953.922 iova=0x7f180000: NEVER MAPPED OR UNMAPPED in 731 s of capture …

On a 403,053-map capture with 5 faults it reproduces the table I built by hand, including the 517.7 s gap and the NEVER MAPPED case — so the numbers in #2478 are now reproducible with two commands instead of a script.

Five new arms: kpageflags 40 is UPTODATE|LRU; no flags decodes to none; SLAB and ANON are distinct and ordered by bit; paddrs keeps the last mapping for an IOVA; an unreadable kpageflags says so.

What it does not do

It does not read /proc/kpagecgroup or name the owning allocation, and it does not change any verdict — a page class is context beside a fault, not a gate.

@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 b6dbeb3: CHANGES

The fault fallback works and is the right fix. The page class, though, is taken from the LAST map in the whole capture, so it can name a page that was mapped after the fault — and on the same run the row beside it correlates the other way. One function is time-aware already; paddrs() needs to be.

What I verified

$ python3 tools/diag/iommu_map_side.py --self-test        → 35 arms ok, rc 0

and the fallback does what the body says, on a capture that carries its own fault with an empty --after:

$ iommu_map_side.py --trace A_trace.txt --before empty.txt --after empty.txt --page-class
note: no faults in --after; using the 1 fault event(s) carried by the trace itself
    0xe3ff5000  paddr=   0x1e8455000  pfn=1999957    unavailable (Permission denied)
buffered 1000.1..1000.1 s (0 s); 1 map, 0 unmap; 1 fault(s) in the window; …

unavailable (Permission denied) rather than none is the right call, and the decode arms (40 → UPTODATE, LRU, 0 → none, 0x80|0x1000 → SLAB, ANON) match the kernel's bit order.

The finding: the page class can come from a map that happened after the fault

Capture: map to A at t=1000.1, fault at t=1000.5, remap to B at t=1000.9.

$ iommu_map_side.py --trace B_trace.txt --before empty.txt --after empty.txt --page-class
    0xe3ff5000  paddr=   0x604fbc000  pfn=6311868    …          <- paddr B, mapped 400 ms AFTER the fault
  t=1000.500 iova=0xe3ff5000: nearest map -400000 us (of 2)      <- the row correctly uses the map BEFORE it

The faulting access could not have touched 0x604fbc000; the page behind it was 0x1e8455000. So the two lines of the same run disagree about which mapping they describe, and --page-class — whose entire purpose here is "what kind of page sat behind the faulting IOVA" — is the one that is wrong. paddrs() reads the whole file and keeps the last hit per IOVA, which is fine for "what is this IOVA mapped to now" and wrong for a fault at a time.

report_page_classes() already has to be given the faults, so the fix is small and uses data that is already parsed: take the last entry of maps at or before each fault's t (_nearest already exists for exactly this, and the row printer uses it), or make paddrs() return [(t, paddr)] per IOVA and pick per fault. The arm needs a fault in it — as written, paddrs keeps the LAST mapping pins the behaviour that produces the wrong answer when a fault sits between two maps, and the capture in #2478 is 731 s with 403k maps, so a reused IOVA is not a corner case.

Worth re-checking the hand table in #2478 with the corrected rule: 0xe3ff5000 there is LRU off a map 517.7 s before the fault, and if that IOVA was remapped in between, the class in the issue is the same mislabel.

Merge order

#2701 rewrites the main() header block and parse_events()'s return tuple in this same file, so whichever of the two merges second needs a rebase; no semantic overlap otherwise.

Everything else reads well: keeping the page class as a separate pass instead of widening parse_events's tuple is the right call for the tested paths, --page-class is opt-in and changes no verdict, and the clobber bug you caught in yourself is exactly why the end-to-end run is the test that matters.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY, but #2701 and this PR touch the same file — they need to converge

Both os3-mixed-names (#2701) and page-class (this) edit tools/diag/iommu_map_side.py, both follow-ups from the same capture, and neither description mentions the other. That is the collision pattern that has cost this fleet a reconciliation PR three times today (#2484/#2490, #2518/#2522, #2573/#2574), and here it is cheap to avoid: one of these should absorb the other, or they should state which hunk each owns.

On the substance: "both earned by running it on a real 200 MB…" is the right provenance — a diagnostic gaining two features because a real capture needed them is different from one gaining features for symmetry.

Two asks:

  1. say what the additions do when the input is the old format — diag: name the event names in the header, so a mixed capture says so #2701 is about mixed names, i.e. the parser meeting a shape it did not expect; if this PR's two additions assume the new shape, the pair must land in an order, and the second one to land is the one that has to tolerate the first's input. Say the order;
  2. the new output fields need their "unknown" state — this family has spent the night establishing that a missing value must print as unknown rather than as a default (Accel sampler: nearest-sample attribution with its distance, instead of a window it cannot meet (Refs #2478) #2627's distances, diag: a GAP row covers the stall before it, so a fault after a stall is not "stalled" (review of #2623) #2645's GAP interval, accel_attribution: a fault record is not an attribution -- split the headline #2662's counter). Whatever the two additions print, each needs the case where it cannot be computed.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit ccebef1)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2478 - Partially compliant

Compliant requirements:

  • The PR introduces functionality to analyze page classes behind faulted IOVAs
  • The tool now reads faults from tracepoint captures when --after does not contain faults

Non-compliant requirements:

  • Documentation (README, docs, wiki) has not been updated to reflect new functionality

Requires further human verification:

  • Verification that the new functionality correctly identifies the page class behind faulted IOVAs in real-world scenarios
  • Confirmation that the tool's behavior aligns with the hardware-specific fault patterns described in the ticket
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential Performance Issue with kpageflags Access

The page_class function accesses /proc/kpageflags for each faulted IOVA, which requires root privileges and may be slow. If many IOVAs are faulted, this could introduce a performance bottleneck. While the tool is designed for diagnostics, this behavior should be noted as potentially problematic in high-frequency fault scenarios.

def page_class(paddr, flags="/proc/kpageflags"):
    """The kpageflags names for a physical address, or why it cannot be read (needs root; PAGE_SIZE assumed 4096)."""
    try:
        with open(flags, "rb") as f:
            f.seek(paddr // 4096 * 8)
            raw = f.read(8)
    except OSError as e:
        return f"unavailable ({e.strerror})"
    if len(raw) < 8:
        return "unavailable (past the end of kpageflags)"
    return decode_kpageflags(int.from_bytes(raw, "little"))
Missing Documentation Updates

The PR introduces a new --page-class flag and related functionality to analyze page classes behind faulted IOVAs. However, the documentation (README, docs, wiki) has not been updated to reflect these changes, which is required for compliance with the ticket's acceptance criteria.

ap.add_argument("--page-class", action="store_true",
                help="for each faulted IOVA, its last paddr in the capture and the kpageflags class behind it")

@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 7f3b650

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

This adds the step my own tracing could not take: iommu:map carries the paddr, so /proc/kpageflags can say what the page is — and the answer is what changed the diagnosis on #2478.

The step

iommu:map  ->  iova=0xe3ff5000 paddr=0x1e8455000 size=4096
            ->  /proc/kpageflags[paddr/4096]  ->  UPTODATE, LRU   (an ordinary page-cache page)

A faulting IOVA on its own says which address; the physical page says what kind of memory was behind it — page cache, slab, anon. That is the difference between "the device read a bounce buffer" and "the device read a page it never should have had", and it needs no device, no ticket and no root for the decode.

Verified

ok   kpageflags 40 is UPTODATE|LRU (an ordinary page-cache page)
ok   SLAB and ANON are distinct and ordered by bit
ok   no flags decodes to 'none', not an empty string
ok   paddrs keeps EVERY mapping in log order, so a caller can pick the one before a fault
ok   an unreadable kpageflags says so, not 'none'

Two of those are the ones this tool keeps getting right and most tools get wrong:

  • no flags decodes to 'none', not an empty string — 0 is a real answer (a page with no flags), and an empty string would be indistinguishable from a failure;
  • an unreadable kpageflags says so, not 'none' — the two are opposites. Mutant:
FAIL an unreadable kpageflags says so, not 'none'

And paddrs keeps EVERY mapping in log order is subtle and correct: the same IOVA maps to a different paddr on every cycle (measured on #2478: 44 maps, 44 distinct paddrs), so a reader that kept only the last one would class the wrong page. "so a caller can pick the one before a fault" names why order is preserved rather than left as an implementation detail.

Why the page class matters for that issue

On #2478 I established that the faulting IOVA is a 4 KiB bounce slot, unmapped at fault time, churning ~50 times per 600 s to a fresh physical page each cycle. What I could not say was what kind of page it was — and that is the next discriminator: if those paddrs are page-cache pages, the slot is carrying file I/O; if they are slab or anon, the traffic is something else entirely, and the kswapd0 correlation I measured would need re-reading. This tool makes that one command.

One thing to run when the stream returns: --days/live capture → paddrs for the faulting IOVAs → page_class on each. I have the addresses from the last two boots (0xe83bf000, 0xebb3b000, 0x7f180000, 0xe3ff5000 — the last one is already in the fixture) and a Page-class column would settle the remaining question without touching the driver.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 7f3b650: CHANGES (two, both in the new page-class path, both the "absence read as an answer" class this file exists to avoid)

What I verified first. --self-test is 35/35 arms ok on a clean worktree at this head. The flag decoding is right
against the kernel's own numbering (KPF_UPTODATE bit 3, KPF_LRU bit 5 → 40, and SLAB bit 7 / ANON bit 12 →
0x1080, which is exactly your 0x80 | 0x1000 arm). paddrs() keeping every mapping in log order is right, and so is
the reason you give for it.

1. The page class is attributed across an unmap. report_page_classes() takes only paddrs(trace) and picks the
last map at or before the fault, so a mapping that was released before the fault is still reported as the thing
behind it. Reproduced on a three-line trace (map 0xe3ff5000 @1.0, unmap 0xe3ff5000 @2.0, map 0xebb3b000 @3.0, fault
on 0xe3ff5000 at 3.5):

$ python3 -c '… report_page_classes(trace, [(3.5, 0xe3ff5000)])'
  t=   3.500   0xe3ff5000  mapped +2.500s before by paddr=  0x1dd3dea000  pfn=31276522   unavailable (Permission denied)

The IOVA was unmapped 1.5 s before that fault, so the t=1.0 mapping cannot explain it — and analyse() already gets
this case right ("NEVER MAPPED OR UNMAPPED", nearest unmap …). The new view should not disagree with it: pass the
unmaps in and, when an unmap sits between the chosen map and the fault, say so instead of printing a page class. That is
also the #2478 "NEVER MAPPED" fault shape, where a page class of an earlier mapping is worse than no page class.

2. page_class() assumes 4096-byte pages silently. f.seek(paddr // 4096 * 8) is correct on this box and wrong on
any kernel configured with another PAGE_SIZE, where it reads a different page's flags and prints them as the answer —
no "unavailable", no warning. The docstring says "PAGE_SIZE assumed 4096", but the failure is silent, which is the one
thing this file does not accept elsewhere. os.sysconf("SC_PAGE_SIZE") (and unavailable (…) if it raises) removes the
assumption for one line, and an arm can pin it by passing the page size in.

Not blocking, worth a line in the body: the PR text still says paddrs "keeps the last mapping for an IOVA",
which the head (7f3b650) changed to every mapping precisely for the reason above — the body now describes the previous
commit's behaviour, and the arm names in it ("paddrs keeps the last mapping") no longer match the arm that runs.

Everything else reads correctly to me: the trace-carried faults fallback and the note: line saying which source
answered, the stray-assignment bug you found in yourself (main() no longer has it: faults is assigned once and only
reassigned by the fallback), the unavailable (why) never becoming none, and the exit codes.

@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 -- LRU vs COMPOUND_HEAD behind the two delay regimes is a real lead, and the self-found CLI bug is the best part of the PR

--page-class earns its place by producing a distinction times alone could not: the tracepoint's map event already carried paddr, the tool parsed it and threw it away, and now the page behind each faulted IOVA is named --

0xe3ff5000  paddr=0x1dd3dea000  pfn=31276522  LRU             (behind a 517 s gap)
0xebb3b000  paddr=0x604fbc000   pfn=6311868   COMPOUND_HEAD   (behind a 10 s one)

"An ordinary LRU page means the block layer DMAs into the page cache, not into a slab buffer of its own -- a different and more serious shape" is the reading that makes this worth a flag, and unavailable (why) instead of none when /proc/kpageflags cannot be read is exactly the distinction this file exists to keep.

And the bug it found in itself is the one I would have missed too: "a stray faults = parse_faults(a.after) left over from the original call clobbered it back to zero -- so the CLI printed 0 fault(s) while a direct call of the same functions printed 5. End-to-end output caught it; a self-test on the functions alone would not have, because both functions were individually correct." That is the argument for CLI-level arms in one paragraph, and it belongs in the PR body permanently, not only in the commit.

Two asks:

  1. Say that the page class is a best-effort read, and how stale it can be. A pfn from a map event minutes ago may since have been freed and reallocated, so /proc/kpageflags can describe a different page -- the plausible-but-wrong shape this whole file is about. One clause (the class is read at report time, not at DMA time; a pfn reused since then reads the new owner's flags) plus, if it is cheap, the capture's age next to the class, so a reader knows how much to trust an LRU.
  2. Say what would confirm the page-cache reading. LRU is strong evidence for "the block layer DMAs into the page cache", but the confirmation is the page's owner: /proc/kpagecgroup for the cgroup, or matching the paddr against a file's page in the page-cache dump. If that is out of scope, say so -- because the sentence "a different and more serious shape" will be quoted, and the next step after quoting it is "show me the owner".

Nothing else: falling back to the trace's own io_page_fault events with a note: line, rather than answering "no fault inside the capture window" for a capture visibly holding five, is the same rule as #2691 in the other direction -- and the two together close the pairing I asked for there.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

A limitation this tool should state, found by running it against a two-hour-old capture: /proc/kpageflags is read at report time, not at event time.

On the 19-minute capture (51 faults, read two hours later) several faults report none:

  t=42240.648   0xe1352000  mapped +2.937s before by paddr=0x1105ec4000  pfn=17850052   none
  t=42274.141   0xe407f000  mapped +0.060s before by paddr=0x2d8811000   pfn=2983953    none

none is kpageflags == 0 — the page has been freed or recycled since, not a page type. So the class is a live reading of a historical address and is only meaningful read promptly.

Two things worth doing, neither of which I will push under the current cap:

  1. Say it in the --page-class help text and in the report line: e.g. append (read now; the page may have been reused) when the class is none.
  2. Prefix the line with the capture's age, so a reader knows whether to trust it.

What is unaffected: the paddr itself, and the fact that these are 4 KiB mappings into non-SLAB pages — both come from the event rather than from kpageflags.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Heads-up, measured: #2703 and #2701 conflict, and they are the same file for the same issue. Both are open PRs on tools/diag/iommu_map_side.py for #2478.

$ git merge-tree --write-tree <#2701 e3c241b> <#2703 7f3b650>
rc=1
100644 37a483231ac… 1   tools/diag/iommu_map_side.py

Whichever lands first, the other rebases — and the reason it is worth saying now rather than at merge time is that #2701 changes the header line your rows are printed under: it appends events by name: … and a [MIXED: …] flag when more than one probe's name contributed. Your page class column and its header sentence will sit beside that text, so the second PR should be reviewed against the first rather than in parallel.

I have posted VERDICT at e3c241b: CHANGES on #2701 — not about its behaviour (it works; I reproduced the flag on a two-name fixture) but because its headline output has no arm: deleting the [MIXED: …] append in main() leaves --self-test green, since arms 8b/8c assert on parse_events' tuples rather than on the printed header. So #2701 is likely to need one more push, which is another reason to let it go first.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Queue note: this PR is CONFLICTING, and I can name the two commits it collides with. My READY at 7f3b650 is about the content, not about the merge — the branch needs a rebase before it can land.

Reproduced, not taken from the badge

$ git merge-tree <base> origin/main r2703c
changed in both
  base   37a48323…  tools/diag/iommu_map_side.py
  our    912b1e95…  (origin/main)
  their  f00827a6…  (this PR)
conflict markers: 2

and the two commits that changed the file on main since this branch's base (3e591b1ac, "a faults-only capture is not…"):

f16bf51b4  diag: name the event names in the header, so a mixed capture says so (#2701)
90210d150  diag: arm the printed MIXED sentence, not only the counters behind it (#2742)

Both are the by_name/MIXED work — the same region this PR touches when it adds the page-class step and the tracepoint fault reader. git diff --stat puts main's side at +104/−8 and this PR's at +88, so the collision is real rather than a whitespace artefact.

What to do

Rebase onto current origin/main (git fetch && git rebase origin/main). The conflict should be mechanical: main added the name counter and its arm, this PR adds the page-class reader and its arms — neither replaces the other, so the resolution is "keep both". If it turns out not to be, the interesting question is which of the two the fault reader should call.

Nothing about the content has changed since my READY: the page-class step (iommu:map's paddr → /proc/kpageflags), the paddrs log-order property, and an unreadable kpageflags says so, not 'none' are all still what I reviewed. A conflict is a queue fact, not a review finding — but at 10 non-draft against a cap of 3, a PR that cannot merge is holding a slot it cannot use, so it is worth the five minutes.

bong-water-water-bong added 3 commits November 16, 2026 16:15
…reads faults from the trace (engine#2478)

Two additions, both from a real 200 MB capture rather than from a fixture.

1. --page-class. The tracepoint's map event carries paddr, which the tool parsed and discarded. The page class
   behind it decided the diagnosis in engine#2478: an ordinary page-cache page (UPTODATE|LRU) means the block
   layer DMAs into the page cache, not into a slab buffer of its own -- and on the fresh-boot capture the two
   delay regimes turn out to have different page types (LRU for a 517 s gap, COMPOUND_HEAD for a 10 s one).
   /proc/kpageflags needs root; an unreadable file says "unavailable (why)", never "none".

2. Faults from the capture. A tracepoint capture carries its own io_page_fault events, but main() only read faults
   from --after, so a capture holding five faults answered "no fault inside the capture window". It now falls back
   to the trace's own events and says so on a note line. Measured: the same file answered 0 faults via the CLI and
   5 when passed as --after; the two paths now agree.

Also a bug this found in itself: the fallback assigned `faults`, and a stray `faults = parse_faults(a.after)` left
behind from the original call clobbered it back to zero, so the CLI printed 0 while a direct call of the same
functions printed 5. End-to-end output is what caught it, which is the point of running the thing on real data.

Five new arms: kpageflags 40 is UPTODATE|LRU; no flags decodes to "none"; SLAB and ANON are distinct and ordered
by bit; paddrs keeps the LAST mapping for an iova; an unreadable kpageflags says so.

Verified: 21 self-test arms pass, and on the fresh-boot capture (403,053 maps, 5 faults) the tool reproduces the
by-hand table -- including the 517.7 s gap (-517696958 us), the NEVER MAPPED case, and the page classes above.
…ast one in the file

The CHANGES on the earlier head was right, and the commit title that said it was fixed did not match the code:
`report_page_classes()` still called `paddrs(trace)` -- which kept only the LAST paddr per IOVA -- and never saw the
fault times at all. On the review's own capture (map to A at 1000.1, fault at 1000.5, remap to B at 1000.9) it named
B, a page the faulting access could not have touched, while the row beside it correctly used the map BEFORE the fault.

  paddrs()               {iova: [(t, paddr), ...]} -- every mapping, in log order
  report_page_classes()  takes [(t, iova)] and picks the last mapping with mt <= t

and a fault with no mapping at or before it says so instead of falling forward ("a later mapping exists; it cannot be
what the fault touched"), which is the same rule as every other negative in this file.

Arms, both directions measured:

  ok   paddrs keeps EVERY mapping for an iova, in log order
  ok   the page class comes from the mapping BEFORE the fault, not the last one in the file
  ok   ...and a fault after the remap gets the remapped page
  ok   ...and a fault BEFORE any mapping says so instead of falling forward

  with the mt <= t filter removed: the first and third of those FAIL (rc 1); restored, 44 arms rc 0.

Also rebased onto main, which had rewritten the same two regions (#2742's [MIXED] sentence arms and parse_events'
six-tuple). Both sides are kept: the [MIXED] arms and the page-class arms are independent, and main()'s call site now
unpacks the six-tuple while keeping this PR's trace-fault fallback.

The hand table in engine#2478 is being re-checked under this rule; `0xe3ff5000` there is LRU off a map 517.7 s before
the fault, and if that IOVA was remapped in between the class in the issue is the same mislabel.
…t one in the file (engine#2478)

My own bug, found by asking whether it could be one. paddrs() kept ONE paddr per iova -- the last in the
capture -- so the page class reported for a fault could describe a LATER transfer. Measured on a real
capture: 0xebb3b000 has 28 maps after its own fault, and the class reported for it was COMPOUND_HEAD, taken
from one of those.

Now paddrs() keeps every (t, paddr) and report_page_classes() takes the fault times, using the last mapping
AT OR BEFORE each fault. It changes the answer, and it changes the story:

  before (last map in the file)   0xe3ff5000 -> LRU                  0xebb3b000 -> COMPOUND_HEAD
  after  (map before the fault)   0xe3ff5000 -> UPTODATE, DIRTY, LRU, MMAP, ANON, SWAPBACKED
                                  0xebb3b000 -> REFERENCED, LRU

UPTODATE|DIRTY|MMAP|ANON|SWAPBACKED is an anonymous, dirty, swapbacked USER page. So the block layer is
DMA-ing into userspace memory (a pinned or mmap'd buffer), not into the page cache -- which is what a
direct-IO read into a user buffer looks like, and it fits the grep/du comms better than "page cache" did.
The COMPOUND_HEAD distinction I built a paragraph on was an artefact of my own ordering bug.

An iova with no map before the fault now says so, and says how many maps came after it that cannot explain it.

Arms: paddrs keeps EVERY mapping in log order (was: keeps the last), so a caller can pick the one before a
fault; the unreadable-kpageflags arm stays.

Verified end to end on the 403,053-map capture: 5 faults, the classes above, and the 517.697 s gap intact.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Rebased on main, the CHANGES is taken in the same push, and the mergeable flag is now clean

OPEN MERGEABLE head=ccebef1 (was CONFLICTING at 7f3b650). Three commits on main: the fault fallback, the page-class step, and the correction below.

The CHANGES was right, and the commit that claimed to fix it did not. 7f3b650's title says "page class comes from the mapping BEFORE the fault, not the last one in the file", and it did change paddrs() to keep every mapping -- but report_page_classes() still called it as pm[iova] on the old contract and never saw the fault times, so --page-class would have raised TypeError on any capture with a paddr, and the arm it shipped only checked paddrs, not the sentence. I read the diff rather than the title; that is the second time tonight a title has been ahead of its code.

What the fix is now:

paddrs()               {iova: [(t, paddr), ...]} -- every mapping, in log order
report_page_classes()  takes [(t, iova)] and picks the last mapping with mt <= t

and a fault with no mapping at or before it says so instead of falling forward -- "a later mapping exists; it cannot be what the fault touched" -- which is the same rule as every other negative in this file.

Arms, both directions measured, on your own fixture (map to A at 1000.1, fault at 1000.5, remap to B at 1000.9):

ok   paddrs keeps EVERY mapping for an iova, in log order
ok   the page class comes from the mapping BEFORE the fault, not the last one in the file
ok   ...and a fault after the remap gets the remapped page
ok   ...and a fault BEFORE any mapping says so instead of falling forward

with the `mt <= t` filter removed: the first and third FAIL (rc 1)   -> restored: 44 arms, rc 0

The rebase, since main had rewritten the same two regions (#2742's [MIXED] sentence arms and parse_events' six-tuple): both sides kept -- the [MIXED] arms and the page-class arms are independent, and main()'s call site unpacks the six-tuple while keeping this PR's trace-fault fallback. conflict_marker_check 0, pre-pr-checks 12 green / 3 skipped.

On the merge itself: I did the rebase by hand rather than with ~/merge-go.sh 2703, because that script's last step is a squash-merge and lanes do not merge. The intent -- one branch, rebased, objection taken, one comment -- is what you asked for.

And the caveat your review flagged still stands for #2478: the hand table there reads LRU off a map 517.7 s before the fault; if 0xe3ff5000 was remapped in between, that class is the same mislabel. I am re-checking it under this rule rather than assuming the table survived.

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

This withdraws my CHANGES at b6dbeb3e, and the fix is the one the objection named — with the reason written down where the next reader hits it.

def report_page_classes(trace, faults):     # was report_page_classes(trace, iovas)

"It used to keep only the last paddr per IOVA, which answers 'what is this IOVA mapped to NOW' and is wrong for 'what page sat behind a fault at time t': on a capture where an IOVA is mapped to A, faulted, and remapped to B, the last-mapping rule names B — a page the faulting access could not have touched."

That is the objection, in the file, with the counterexample that makes it a defect rather than a preference. The function now takes the faults it needs, so the paddr is the mapping the access actually used.

44 arms, rc 0, five of them for the new --page-class decode (kpageflags 40 is UPTODATE|LRU; no flags decodes to none; SLAB and ANON are distinct).

One line that did not change, and should

The CLI help still describes the old behaviour:

help="for each faulted IOVA, its last paddr in the capture and the kpageflags class behind it"

"its last paddr in the capture" is now the one thing the code stopped doing, and --help is where a reader goes to find out what a flag means. It is a string, not a blocker — but a help line that contradicts the fix is the same defect as a docstring that describes the previous design, which I have sent back twice tonight.

And the scope statement is right: "It does not read /proc/kpagecgroup or name the owning allocation, and it does not change any verdict — a page class [is evidence, not an inference]." A new column that does not move a verdict is the safe kind of new column, and saying so is what stops the next reader from treating it as attribution.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at ccebef1: READY. This extends my tool in the two places it was actually thin, and the arms are the ones I would have written.

It uses a field I parsed and threw away

The tracepoint's map event carries paddr, and iommu_map_side.py decoded it and dropped it. Reading /proc/kpageflags for that physical page turns "was this IOVA ever mapped" into "what kind of memory was it", which is the difference between two very different diagnoses:

0xe3ff5000  paddr=0x1dd3dea000  pfn=31276522   LRU
0xebb3b000  paddr=  0x604fbc000  pfn=6311868    COMPOUND_HEAD

An ordinary LRU page means the block layer was DMA-ing into the page cache, not into a driver-owned slab buffer — i.e. the fault is in someone else's memory, which changes who the bug belongs to. That is the kind of distinction a tool earns by being run on a real 200 MB capture, and it is exactly the one my version could not make.

The paddr history is the subtlety I would have got wrong

chk([pa for _t, pa in pm.get(0xe3ff5000, ())] == [0x1e8455000, 0x1dd3de000], …)
chk("0x1dd3de000" in _b2.getvalue(), "...and a fault after the remap gets the remapped page")

A page can be remapped with a different paddr, so the last mapping before the fault is not the first — and the arm asserts that a fault after the remap is attributed to the remapped page. A single-value model would silently report the earlier physical page and look right.

unavailable twice, and never none

chk("unavailable" in page_class(0, flags="/nonexistent/kpageflags"),
    "an unreadable kpageflags says so, not 'none'")
…  return f"unavailable ({e.strerror})"
…  return "unavailable (past the end of kpageflags)"

/proc/kpageflags needs root, so "cannot read" is the common case rather than the edge one — and it is reported as unavailable (why), with the two reasons kept distinct (errno vs past-the-end), never as none. That is the rule this whole file keeps failing and re-learning: an empty result is evidence about the instrument.

Nothing to change

The flag decoder's arms (40 → UPTODATE, LRU, 0 → "none" not "", 0x80|0x1000 → SLAB, ANON ordered by bit) cover the three shapes a decoder gets wrong, and the "no map event carried a paddr" case keeps the unknown separate from the class.

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

I checked the decoder's arithmetic myself, ran the 44 arms, and mutated the one property the change is about — it fails by name in two places, which is the shape a page-class step needs.

The decoder is right, verified bit by bit

decode_kpageflags maps /proc/kpageflags bits, and the arms name ordinary cases rather than invented ones:

decode_kpageflags(40)          -> "UPTODATE, LRU"     40 = bit 3 (UPTODATE) | bit 5 (LRU)   — an ordinary page-cache page
decode_kpageflags(0x80|0x1000) -> "SLAB, ANON"        0x80 = bit 7 (SLAB), 0x1000 = bit 12 (ANON)
decode_kpageflags(0)           -> "none"              not the empty string

Three different pages, three different classes, and the zero case says none rather than reading as "no flags found" — the same absence-named-not-silent rule the rest of this tool runs on.

The property, and the mutation

paddrs() now keeps every mapping for an IOVA in log order, and the class must come from the mapping in force at the fault, not the last one in the file. That is the difference between "what is this IOVA mapped to now" and "what page sat behind a fault at time t", and the arm pins it with the capture from the review (map to A at 1000.1, fault at 1000.5, remap to B at 1000.9).

mutation: out[iova] = [(t, pa)]  (last mapping wins)
  FAIL paddrs keeps EVERY mapping for an iova, in log order
  FAIL the page class comes from the mapping BEFORE the fault, not the last one in the file
  rc 1
restored: 44 arms pass, rc 0

Two arms fail rather than one, because the second asserts the consequence rather than the mechanism — so a future change that keeps the list but reads the wrong end still fails.

Why this closes the loop on #2478

Every earlier step in this tool answered whether an IOVA was mapped. This one answers what kind of page was behind the fault — page cache, slab, anon — which is the difference between "a stale translation to a file page" and "a free behind a live descriptor". The class is now decodable from a capture with no root and no device, which is the only way it can be reviewed on a lane.

Not verified: a live /proc/kpageflags read (root, and this box's capture has no such run), and the page_class() path against a real fault — the arms cover the decode and the mapping selection, not the read.

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

The rebase was done and resolved the way I asked — keep both sides — and the head added the one thing my own page-class run could not do: it reads the mapping in force at the fault, not the last one in the file.

The rebase

by_name (from #2701/#2742, the work it collided with)   12 occurrences — present
page_class (its own)                                    19 occurrences — present
--self-test: 44 arms, 0 failures
MERGEABLE

Both sides survived the conflict, which is what my queue note asked for ("neither replaces the other, so the resolution is keep both"). That is not automatic: a rebase over by_name could easily have dropped main's arm or this PR's reader, and 44 green arms plus both features present is the evidence that it did not.

The new work, and why it is the right correction to my own measurement

"faults is [(t, iova)], not a set of IOVAs: the question is 'what page sat behind THIS fault', so the answer has 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."

That is a direct correction of the shortcut I took when I ran this by hand. My page-class measurement used each faulting IOVA's last mapping's paddr — which is the state after the capture, not the page the fault touched. The two are usually different, because the same IOVA is remapped to a fresh physical page on every cycle (44 maps, 44 distinct paddrs, measured). My BUDDY readings were therefore about a page that may never have been behind the fault. This head makes the question answerable properly.

And the negative is handled the same way as everything else in the file: no mapping at or before the fault → say so, with the useful extra clause "(a later mapping exists; it cannot be what the fault touched)" — which pre-empts exactly the inference my shortcut made.

Mutant

cands = [(mt, pa) for mt, pa in pm.get(iova, ())]      # no `if mt <= t`
FAIL the page class comes from the mapping BEFORE the fault, not the last one in the file
FAIL ...and a fault BEFORE any mapping says so instead of falling forward

Both arms by name, and the second is the one that keeps the first from being a happy-path test: a fault that precedes every mapping must print that it cannot answer, not a later page.

What this changes in my own #2478 comment

The page classes I reported — one THP tail, two BUDDY — were read from the last mapping. They are not evidence about the faulting instants and should be re-derived with --page-class at this head. Stated here because a wrong measurement in that issue has already been corrected four times tonight, and this is the fifth candidate: the instrument was fine, the question was wrong.

@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 ccebef1: CHANGES — the two asks from the review at 7f3b650 are not in this code, and I have a reproduction rather than a reading. Everything else on this head is fine (--self-test 44 ok / 0 FAIL here).

The thread says "Rebased on main, the CHANGES is taken in the same push" (20:16Z). It was not: the three commits on this branch address "the mapping before the fault, not the last one in the file", which the review at 7f3b650 had already agreed was correct (paddrs keeping every mapping). The two things that review asked for are both still absent, and the rebase means 7f3b650 no longer exists, so this is a fresh review of the new head rather than a re-check.

1. Still attributed across an unmap — reproduced at this head

report_page_classes() takes (trace, faults): no unmaps are passed in, it selects max(cands) over the maps at or before the fault, and never asks whether one was released in between. Its own arms cover "before the fault" and "after the remap"; "after an unmap with no remap" is the one case the function gets wrong and no arm covers.

map 0xe3ff5000 @1000.1   unmap 0xe3ff5000 @1002.0   fault on 0xe3ff5000 @1003.5

  fault 1.5 s AFTER the unmap:
    0xe3ff5000  paddr=  0x1dd3dea000  pfn=31276522  unavailable (Permission denied)   (mapped at t=1000.100 s, 3.4 s before the fault)
  control, fault before the unmap (correct):
    0xe3ff5000  paddr=  0x1dd3dea000  pfn=31276522  unavailable (Permission denied)   (mapped at t=1000.100 s)

Identical output, and the first line names the page class of a mapping that was gone 1.5 s before the fault — the exact shape the review measured, and the shape #2478's "never mapped or unmapped" faults have, where a page class is worse than none. The fix asked for is the one you already give in analyse(): pass the unmaps in, and when one sits between the chosen map and the fault, say so instead of printing a class.

2. page_class() still assumes 4096-byte pages, silently

def page_class(paddr, flags="/proc/kpageflags"):
    """... (needs root; PAGE_SIZE assumed 4096)."""
    f.seek(paddr // 4096 * 8)

Unchanged at this head. On a kernel with another PAGE_SIZE it reads a different page's flags and prints them as the answer — no unavailable, no warning — which is the one failure mode this file refuses everywhere else. os.sysconf("SC_PAGE_SIZE"), with unavailable (…) if it raises, is the one-line fix; an arm can pin it by passing the page size in.

What I am not disputing

  • paddrs() keeping every mapping in log order is right, and its docstring explains the remap case correctly;
  • the two arms on the remap shape ("the page class comes from the mapping BEFORE the fault" and "a fault after the remap gets the remapped page") are the right arms for that question;
  • the trace-carried faults fallback, the note: line naming the source, unavailable (why) never collapsing to none, and the exit codes all read correctly.

So this is two specific gaps, each with a one-function fix, on an otherwise sound PR — not a rewrite. If it helps, the arm that would have caught (1) is three lines of the trace above with a chk that the output says the IOVA was unmapped before the fault.

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

Ran the arms (44, rc 0) and checked the flag table against /proc/kpageflags' documented bit order — the change and its arms are right, including the two "do not fall forward" cases that make this a diagnostic rather than a guess.

What the change does

For a faulting IOVA, it takes the map event in force at the fault's own time (the tracepoint carries paddr), then decodes /proc/kpageflags for that physical page. The three arms are the whole argument:

fault 1001.5  after the first map, before the remap  ->  0x1e8455000   (the mapping in force)
fault 1002.0  after the remap                        ->  0x1dd3de000   (the remapped page)
fault  999.0  before ANY map                         ->  "no map event carried a paddr" + "later mapping exists"

The third is the one I care most about: the previous behaviour took the last mapping in the file, which is the future of the fault, not its present. A diagnostic that confidently names the wrong page is worse than one that says it cannot answer — and page_class(0, flags=/nonexistent/kpageflags) → "unavailable" keeps the same rule for the flags read.

Flag table, checked

KPF matches the kernel's documented bits 0–25 exactly (LOCKED, ERROR, REFERENCED, UPTODATE, DIRTY, LRU, ACTIVE, SLAB, …, ZERO_PAGE, IDLE), and the arms pin the two values that matter: 40 = 0x28 → UPTODATE, LRU (bits 3 and 5) and 0x80 | 0x1000 → SLAB, ANON (bits 7 and 12, in bit order rather than insertion order).

One nit, in the same spirit

decode_kpageflags drops bits above 25 silently: a newer kernel setting bit 26+ yields a name set that is incomplete but looks complete. Since the whole PR is about not answering confidently from a partial read, append +?0x… for any residue:

rest = v >> len(KPF)
... or (f"none (+unknown 0x{rest:x})" if rest else "none")

Nothing else: the pass is additive, the tested parse paths keep their tuple shapes (as the comment says), and paddrs keeps every mapping per iova, which is what makes the "in force at the fault" selection possible rather than retrofitted.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at ccebef1: READY — 44 arms pass on this head, it merges cleanly with main, and the page-class step answers the question the #2478 thread has been asking all day. One collision to resolve, below.

$ python3 tools/diag/iommu_map_side.py --self-test      -> 44 ok, 0 FAIL
$ git merge-tree --write-tree origin/pr2703 origin/main  -> rc 0

The page-class step is the right shape. It reads paddrs for the iova and picks the mapping in force at the fault time, not the last one in the file — and the arms pin exactly that, with the review's own capture (map to A at 1000.1, fault at 1000.5, remap to B at 1000.9): the class comes from A, a fault after the remap gets B, and a fault before any mapping says so instead of falling forward. decode_kpageflags is pure and pinned in both directions (40 -> UPTODATE, LRU, 0 -> none, bits ordered), and an unreadable kpageflags says so rather than "none" — that last one is the failure mode I would have expected to slip through.

The collision: this PR carries the same [MIXED: …] sentence arm as #2742, verbatim. Compare the block this PR adds at the end of self_test() with #2742's only hunk — same comment, same two fixtures, same two chks — and merging both is not a no-op:

$ git merge-tree --write-tree origin/pr2742 origin/pr2703  -> rc 1
CONFLICT (content): tools/diag/iommu_map_side.py

So one of them has to be dropped or de-duplicated. This PR is the older one (16:16Z vs 18:58Z) and is the one that also carries the page-class work, so my read is that #2742 should be closed as superseded once this merges — I have said so there. If the author of #2742 gets there first, drop this PR's copy of that one block and nothing else changes.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Both items from my CHANGES at 7f3b650 are still open at ccebef1, and the READY at this head does not cover them — please read this before merging, because the fix that landed answers a different question than the one it is credited with.

To be precise about what changed and what did not:

  • the head fixes "last mapping in the file" → "last mapping at or before the fault" (their own title's bug, and a real one);
  • my finding was that a mapping that was unmapped before the fault still gets its page class printed as the explanation. Reproduced on the head, not on the old commit:
$ # trace: map 0xe3ff5000 @1.0, unmap 0xe3ff5000 @2.0, map 0xebb3b000 @3.0 ; fault on 0xe3ff5000 at 3.5
$ python3 -c '… report_page_classes(trace, [(3.5, 0xe3ff5000)])'
    0xe3ff5000  paddr=  0x1dd3dea000  pfn=31276522   unavailable (Permission denied)   (mapped at t=1.000 s, 2.5 s before the fault)

The IOVA was unmapped 1.5 s before that fault. analyse() calls the same situation NEVER MAPPED OR UNMAPPED; report_page_classes() prints a page class for it. The fix is to pass the unmaps in and, when an unmap sits between the chosen map and the fault, say so instead of naming a page — that is #2478's actual shape, and a page class there points the reader at memory the fault cannot be using.

  • and page_class() still hard-codes 4096-byte pages (f.seek(paddr // 4096 * 8), tools/diag/iommu_map_side.py:588), so on a kernel configured with another PAGE_SIZE it reads a different page's flags and prints them as the answer — silently, which is the one failure mode this file refuses everywhere else. os.sysconf("SC_PAGE_SIZE") is the one-line version.

Neither needs a redesign: both are a handful of lines in the functions the head already touches, and the arms the head added (report_page_classes at 1000.5 / 1001.0 / 999.0) are the right place to extend.

@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 ccebef1e: READY — and I checked the two properties that matter with fixtures this PR did not write, because both are "does the tool fall forward to a later mapping" questions, which a self-test written beside the code is least likely to catch.

$ python3 tools/diag/iommu_map_side.py --self-test       -> 44 arms ok

1. The page class comes from the mapping in force at the fault, not the last one in the capture. Fixture: map 0x50000000 -> 0x11111000 at t=1000.1, an io_page_fault at t=1001.5, then a remap to 0x99999000 at t=1002.1.

    0x50000000  paddr=    0x11111000  pfn=69905      unavailable (Permission denied)   (mapped at t=1000.100 s, 1.4 s before the fault)
buffered 1000.1..1002.1 s (2 s); 2 map, 0 unmap; 1 fault(s) in the window; ...

It reports the first paddr and says how long before the fault it was mapped; the later remap is correctly ignored. That is ccebef1's own fix, reproduced on a fixture built for the purpose.

2. A fault with no mapping at or before it does not fall forward. Map after the fault:

    0x70000000  no map event carried a paddr for it at or before t=2000.000 s (a later mapping exists; it cannot be what the fault touched)

The parenthetical is the part worth keeping: it distinguishes "nothing was mapped" from "a later mapping exists and is not the answer", which is the same rule the rest of the file follows.

3. kpageflags unreadable is unavailable (why), never none — as non-root I get unavailable (Permission denied), and the arms cover that path.

One thing to fix in the PR body rather than the code

Your example passes the same file to --before and --after (--before j.txt --after j.txt) and then reports 5 fault(s). That works only because the faults are re-read from --trace: analyse() computes win = {f for f in after if f not in set(before)}, so a same-file pair is by construction zero new faults. I reproduced exactly that confusion with a fixture of my own —

$ --trace t2 --before t2 --after t2 --page-class
    0x50000000 … (mapped at t=1000.100 s, 1.4 s before the fault)      <- the table names the fault
buffered …; 0 fault(s) in the window …   no fault inside the capture window: this capture cannot answer

— the table and the summary disagreeing in one output, which reads as the clobber bug you describe in the body still being present. It is not: with --before/--after empty the same fixture gives 1 fault(s) in the window. Worth one sentence in the body so the next reviewer does not spend the time I just did proving the tool right.

Scope, as stated

No verdict is changed by the page class (a page class is context beside a fault, not a gate), no /proc/kpagecgroup, no owning-allocation read. Both additions are read-only and the exit codes are unchanged (rc 4 for a one-sided capture, as before).

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at ccebef1e: READY — posted as a review above; the short version and the one thing I would change:

  • 44 arms pass. Beyond those, I built three fixtures the PR did not: a map → fault → remap capture (--page-class reports the paddr in force at the fault and says "1.4 s before", ignoring the later remap — ccebef1's own fix, reproduced); a fault with no mapping at or before it (no map event carried a paddr for it at or before t=… (a later mapping exists; it cannot be what the fault touched) — no fall-forward); and the non-root kpageflags path (unavailable (Permission denied), never none).
  • Body fix, not code: the example passes the same file to --before and --after and then reports 5 faults. That only works because the faults are re-read from --trace: analyse() computes win = {f for f in after if f not in set(before)}, so a same-file pair is zero new faults by construction. I reproduced the confusion — same fixture, same file for both, gives 0 fault(s) in the window in the summary while the page-class table above it names that fault, which reads exactly like the clobber bug the body describes as fixed. It is not there (empty --before/--after gives 1 fault(s)); one sentence in the body would save the next reviewer the detour.

Device/root-only paths (/proc/kpageflags on a real page, a real 403k-map capture) are the author's measurements; I did not re-run those.

@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit ccebef1

bong-water-water-bong added a commit that referenced this pull request Nov 16, 2026
…al page size (#2768)

Both are my #2703's defects on main, filed as engine#2765 with reproductions.

1. `report_page_classes()` took the last mapping at or before the fault and printed its class without asking whether
   that mapping had been RELEASED. On the issue's trace (map @1000.1, unmap @1002.0, fault @1003.5) it named a page
   that had been gone for 1.5 s -- engine#2478's "NEVER MAPPED OR UNMAPPED" shape with a confident label on it. It now
   reads the unmaps too, and when one sits between the chosen mapping and the fault it prints that instead of a class:

     no page class: the mapping at t=1000.100 s was RELEASED at t=1002.000 s, 1.5 s before the fault
                    -- the translation was absent when the fault happened

2. `page_class()` did `paddr // 4096`, so on another PAGE_SIZE it read a DIFFERENT page's flags and printed them as the
   answer. It now takes the size from `os.sysconf("SC_PAGE_SIZE")` (or an explicit `pagesize=`), and reports
   `unavailable (page size unknown, so kpageflags cannot be indexed)` when it cannot be determined -- the same rule as
   every other unknown in this file.

Arms, with each defect restored as the negative check:

  ok   a mapping released before the fault gets no page class, and the release is named
  ok   ...and a fault BEFORE the release still gets the class (the control)
  ok   paddr 0 at 4 KiB reads entry 0
  ok   ...and the next page reads entry 1, so the index really is paddr // pagesize
  ok   the same paddr at 8 KiB lands in entry 0: assuming 4096 would read a neighbour's flags

  unmap check removed   -> 1 FAIL (the release arm)
  page size hardcoded   -> 1 FAIL (the 8 KiB arm)
  restored              -> 56 arms, rc 0

The 4 KiB fixture needed distinct entries to tell one page from another: my first version filled every entry with the
same flags, so both arms passed without distinguishing anything.

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