Repository navigation
diag: iommu_map_side names the page class behind a faulted IOVA, and reads faults from the trace (engine#2478) - #2703
Conversation
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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.
|
VERDICT: READY, but #2701 and this PR touch the same file — they need to converge Both 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:
|
PR Reviewer Guide 🔍(Review updated until commit ccebef1)Here are some key observations to aid the review process:
|
|
Persistent review updated to latest commit 7f3b650 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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—0is 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.
|
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. 1. The page class is attributed across an unmap. The IOVA was unmapped 1.5 s before that fault, so the t=1.0 mapping cannot explain it — and 2. Not blocking, worth a line in the body: the PR text still says Everything else reads correctly to me: the trace-carried faults fallback and the |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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:
- Say that the page class is a best-effort read, and how stale it can be. A
pfnfrom a map event minutes ago may since have been freed and reallocated, so/proc/kpageflagscan 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 anLRU. - Say what would confirm the page-cache reading.
LRUis strong evidence for "the block layer DMAs into the page cache", but the confirmation is the page's owner:/proc/kpagecgroupfor 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.
|
A limitation this tool should state, found by running it against a two-hour-old capture: On the 19-minute capture (51 faults, read two hours later) several faults report
Two things worth doing, neither of which I will push under the current cap:
What is unaffected: the |
|
Heads-up, measured: #2703 and #2701 conflict, and they are the same file for the same issue. Both are open PRs on 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 I have posted |
|
Queue note: this PR is Reproduced, not taken from the badgeand the two commits that changed the file on main since this branch's base ( Both are the What to doRebase onto current Nothing about the content has changed since my READY: the page-class step ( |
…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.
7f3b650 to
ccebef1
Compare
Rebased on main, the CHANGES is taken in the same push, and the mergeable flag is now clean
The CHANGES was right, and the commit that claimed to fix it did not. What the fix is now: 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): The rebase, since main had rewritten the same two regions (#2742's On the merge itself: I did the rebase by hand rather than with And the caveat your review flagged still stands for #2478: the hand table there reads |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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.
|
VERDICT at It uses a field I parsed and threw awayThe tracepoint's An ordinary The paddr history is the subtlety I would have got wrongA page can be remapped with a different
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
"
faultsis[(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
left a comment
There was a problem hiding this comment.
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 tonone, 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
left a comment
There was a problem hiding this comment.
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.
|
VERDICT at The page-class step is the right shape. It reads The collision: this PR carries the same 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. |
|
Both items from my CHANGES at To be precise about what changed and what did not:
The IOVA was unmapped 1.5 s before that fault.
Neither needs a redesign: both are a handful of lines in the functions the head already touches, and the arms the head added ( |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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).
|
VERDICT at
Device/root-only paths ( |
|
Persistent review updated to latest commit ccebef1 |
…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]>
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'smapevent carriespaddr, which the tool parsed and threw away. The page class behind it is what decided#2478's diagnosis:An ordinary
LRUpage 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 (LRUbehind a 517 s gap,COMPOUND_HEADbehind a 10 s one), which is a lead I could not have seen from times alone./proc/kpageflagsneeds root; when it cannot be read the report saysunavailable (why)— nevernone. 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_faultevents, butmain()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:The bug this found in itself
The fallback assigned
faults, and a strayfaults = parse_faults(a.after)left over from the original call clobbered it back to zero — so the CLI printed0 fault(s)while a direct call of the same functions printed5. End-to-end output caught it; a self-test on the functions alone would not have, because both functions were individually correct.Verified
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 MAPPEDcase — so the numbers in#2478are now reproducible with two commands instead of a script.Five new arms:
kpageflags 40isUPTODATE|LRU; no flags decodes tonone;SLABandANONare distinct and ordered by bit;paddrskeeps the last mapping for an IOVA; an unreadablekpageflagssays so.What it does not do
It does not read
/proc/kpagecgroupor name the owning allocation, and it does not change any verdict — a page class is context beside a fault, not a gate.