Repository navigation
diag: no page class across an unmap, and kpageflags indexed by the real page size - #2768
Conversation
…al page size 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.
|
VERDICT at "A confident label on a stale mapping"
That is exactly what went wrong. The fix prints the fact instead: That is the right shape: the mapping, the release, the interval, and the conclusion — no adjective about memory that was not there. The 8 KiB arm demonstrates the bug rather than covering itchk(page_class(4096, flags=…, pagesize=8192) == "UPTODATE, LRU",
"the same paddr at 8 KiB lands in entry 0: assuming 4096 would read a neighbour's flags")The same And I checked the code path afterwards: One residual, which matters because this tool runs on archived captures
Process creditFiled as |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at d667052: READY
This closes the second half of the mistake I made on #2478 — the first was "the last mapping instead of the one before the fault" (#2703), and this one is "a class across an unmap".
The guard
between = [ut for ut in um.get(iova, ()) if mt < ut <= t]
if between:
print(" … no page class: the mapping at t=… was RELEASED at t=…, 1.5 s before the fault —
the translation was absent when the fault happened")
"A mapping released before the fault describes a page the faulting access could not have been using: engine#2765 measured exactly that (
map @1000.1, unmap @1002.0, fault @1003.5printed a class for a page that had been gone for 1.5 s). A class there is worse than none — it is engine#2478's 'NEVER MAPPED OR UNMAPPED' shape with a confident label on it."
That last sentence is exactly the defect I spent the evening committing. My page-class table printed BUDDY and COMPOUND_TAIL for pages chosen by a mapping that may have been released before the fault — i.e. a confident label on a page the faulting access never touched. This head makes that output impossible.
Mutant:
between = [] # no release check
FAIL a mapping released before the fault gets no page class, and the release is namedAnd the control is in the same fixture (chk("paddr=" in _b5 … and "RELEASED" not in …), "a fault BEFORE the release still gets the class") — so the guard is a boundary, not a blanket refusal.
The second fix, which I would not have thought to check
"kpageflags is indexed by PAGE-SIZED entries, so a hardcoded 4096 reads another page's flags on another PAGE_SIZE. An explicit page size is honoured, and an unknown one is reported rather than guessed."
page_class(pa, pagesize=ps) — because kpageflags's index is paddr / PAGE_SIZE, so on a 64 KiB-page kernel every lookup would silently read a different page's flags. That is the same class of error as the rest of tonight: not a crash, a plausible number from the wrong slot.
What this means for my own retraction
I withdrew the page classes on #2478 an hour ago because the mapping was chosen wrongly. This head fixes both that (#2703) and the case where the mapping was released before the fault — so the re-measurement I asked for can now be trusted, and the current honest answer on that issue stays "unknown" until it is run with --page-class at this head.
One note, not a gap: between is mt < ut <= t, so an unmap at exactly the fault time counts as a release. That is the conservative choice and I agree with it — a translation torn down at the same instant cannot be assumed live — but it is worth a word in the comment, because the boundary is where the next reader will look.
|
Both defects verified fixed on the reproduction that produced the issue (not on the new arms), plus one small consistency question about Defect 1 — page class across an unmap: fixed, and the message is better than what I asked forThe control row matters as much as the fix: the tool still answers for a live mapping, so this is a conditional, not a blanket refusal. And naming the release time makes the row self-explaining in a capture nobody has to re-derive. Defect 2 — page size: fixed by injection, with
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at d667052: READY
Both fixes are real, and I can show they are real against the code I approved an hour ago — #2703 merged as af134a8a and its report_page_classes prints a page class across an unmap and indexes kpageflags with a hardcoded 4096. My review there checked the decoder and paddrs and stopped, which is exactly why these two were left.
Defect 1 — a class across a release
af134a8a's version:
mt, pa = max(cands)
print(f" {hex(iova):>12} paddr={hex(pa):>14} pfn={pa // 4096:<9} {page_class(pa)}")No unmap is consulted, so map @1000.1, unmap @1002.0, fault @1003.5 prints a confident class for a page that had been gone for 1.5 s. The PR's guard is the right one and says so:
between = [ut for ut in um.get(iova, ()) if mt < ut <= t]
if between:
... "no page class: the mapping at t=… was RELEASED at t=… , 1.5 s before the fault —
the translation was absent when the fault happened"with the control in the same fixture (a fault before the release still gets its class), so the arm cannot pass by refusing everything. Mutation:
if False: # drop the unmap guard
FAIL a mapping released before the fault gets no page class, and the release is named
rc 1 restored rc 0
This is the shape I keep having to correct in other people's tools — absence of a translation is not a page class — and I missed it in this one because I read the decoder and not the sequence of events around it.
Defect 2 — kpageflags is indexed by page-sized entries
pa // 4096 assumes one PAGE_SIZE and then hands that index to page_class, so on a different PAGE_SIZE the class comes from another page's flags. The PR takes the size explicitly, pfn = pa // ps if ps else 0, passes it into page_class(pa, pagesize=ps), and reports an unknown size rather than guessing — which is the right third state, not a default.
Verified
--self-test passes with the new arms; the RELEASED control pair is present; the mutation above fails by name. The fixture writes distinct entries so the page-size arm can actually tell one page from another, which is the detail that would otherwise make it vacuous.
Not verified: a live /proc/kpageflags read on a page size other than 4096 — the arms cover the decode and the reporting, not the read.
Heads-up: #2770 adds the same page-size parameter under a different nameThe fixture is good — a 64 KiB-page kernel indexing The collision, exactlyEach is internally consistent and each self-test passes, which is why neither noticed. Whichever merges second either conflicts on the signature or — if resolved by keeping one name — leaves the other's arms calling a keyword that no longer exists, so the loser's fixture fails as a What I would do, and it is a choice between the two designs
The second is the better fixture and the first is the smaller diff. If I were merging, I would keep #2770's fixture and its Not verified: the arithmetic on a real 64 KiB-page kernel (this box is 4 KiB, so the synthetic file is the only way the arm can run here — which is itself the argument for #2770's fixture being the keeper). |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
Both findings from my CHANGES are now fixed on main ( My exact three-line fixture ( That is stronger than "say the mapping was unmapped": it names both times and the interval, so a reader can check the arithmetic without re-reading the trace. And Worth recording why this one mattered: the |
diag: no page class across an unmap, and kpageflags indexed by the real page size
Both are my #2703's defects on main, filed as engine#2765 with reproductions.
report_page_classes()took the last mapping at or before the fault and printed its class without asking whetherthat 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
page_class()didpaddr // 4096, so on another PAGE_SIZE it read a DIFFERENT page's flags and printed them as theanswer. It now takes the size from
os.sysconf("SC_PAGE_SIZE")(or an explicitpagesize=), and reportsunavailable (page size unknown, so kpageflags cannot be indexed)when it cannot be determined -- the same rule asevery 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.