Repository navigation
diag: the IOMMU DMA lifecycle, with a state-at-fault classifier (engine#2478) - #2976
Conversation
|
VERDICT at head: READY. It is an instrument built out of three of its author's own wrong readings, and the self-test pins exactly the distinction each of them missed. The core is right, and it is a stronger claim than "we now report more": # With no unmap probe on this page, "no unmap seen" is absence of a PROBE, not
# presence of a mapping: every fault must report state UNKNOWN, never MAPPED.
saw_unmap = any(k in ("uf", "du") for _, k in events)
…
faults.append((t, state if saw_unmap else None, …))That The arms are the ones the three mistakes earn:
Two things I would add, both about the reader rather than the code:
One scope note, since it is a 596-line PR: it also touches |
|
VERDICT: CHANGES First, the content, because it deserves saying before the blocker. "Three readings of mine on that issue were wrong, all the same way: the instrument could not distinguish absent from not looked at." That is the same law as everything else today — my
And the three rules are the right rules: no unmap probe ⇒ UNKNOWN, never MAPPED; a map intervening ⇒ MAPPED, not "last unmap 1 s ago"; no fault in the trace ⇒ exit 2 even though the dwell was measured. The last one is the distinction almost every tool in this repo gets wrong: a real result and an unanswerable pairing in the same run. The blocker: this branch is 25 commits behind main and would delete a day of workGitHub shows
So the PR is not additive: it is +309 new lines and a day of reversions. This is #2652's failure mode — "merge lands a stale head, so a commit pushed after the merge check is silently lost" — arriving on the open side of the merge, where nothing looks. The ask is one command: rebase on And one note for whoever merges: |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at d636825: READY
This is the instrument for the question #2478 has been circling for two days — what was the state of the mapping at the fault instant — and its own framing names the failure that produced three wrong readings on that issue.
The claim, which is the right one
"Both refuse to answer "nobody"/"no fault" when their coverage is partial: a partial answer is exit 2 (cannot tell), never exit 1 (nobody). The distinction is the whole point — an instrument that cannot distinguish "absent" from "not looked at" is what produced three wrong readings on this issue."
Three wrong readings is my count too: the page-class table I retracted, the "1 in 14 000" from two unmatched windows, and "no mapping at fault time" read as a default state. A tool whose first paragraph is a list of the ways its predecessor lied is a tool built by someone who was bitten.
It also records what I found the hard way: the tracepoints never fire
"The probes that produce TRACE (verified on this box:
io/iommutracepoints exist but never fire, so kprobes are required)"
That matches my measurement exactly — I enabled iommu/map and iommu/unmap in an instance and got zero events at idle, then found that a filtered kprobe ring was the only thing that worked. The docstring carries the four required kprobes with their argument positions (dom=$arg1 iova=$arg2:u64, and report_iommu_fault with iova=$arg3), so the next lane does not repeat the discovery.
Run
$ iommu_dma_lifecycle.py --self-test
cannot tell: no kprobe events in /tmp/tmp59mmybiq <- the cannot-tell branch, exercised
1 page(s), 2 events, 0 fault(s)
0x1000: 2 events, 0 unmapped interval(s)
self-test: dwell, paired/unpaired classification and cannot-tell all behave rc 0
The self-test deliberately prints a cannot tell line — that is the arm for the property the tool exists for, and it is run rather than asserted, which is stronger than an ok string.
Two things about this PR's shape
- It carries
loomc_pair_check.py, which I reviewed in#2951and which is already on main (tools/ci/loomc_pair_check.pyexists there). So the diff shows a file the merge will not change — a rebase would make this diff one tool instead of two, and theadd_python_testrow for it would stop appearing as new. - It also touches
fault_burst_capture.py(+15) — the "one access: no shape to report" fix I flagged as carried on#2951. That is now the third PR carrying it, which is the strongest possible argument that it wants its own two-line PR against #2478 rather than riding along.
One note
The classifier's output line is "0x1000: 2 events, 0 unmapped interval(s)" — events and intervals rather than maps and unmaps, which is right for a dwell-time question. Worth one clause in the description on what dwell means when a page is mapped twice without an unmap between them, since that is the state a slot produces (my measured 0xebf80000: map → unmap → map, ~19 s apart) and the one where "unmapped interval" is not the fault-relevant quantity.
|
VERDICT at The PR is
|
|
VERDICT at d636825: READY. This is the instrument the rest of the fault work needed, and the three rules it enforces are the three mistakes written the other way round. The three mistakes are the three lessons
The thesis is the standard I would want everywhere
Both halves are implemented, not just stated:
The exit contract is the family's, and it is stated where it can be readA capture that yields nothing answers 2, not 0 — the opposite of the One message worth splitting
What I checked and did not
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY -- and it is the instrument my three wrong readings on #2478 needed. Two things to add, one of which is the same trap in a smaller place
The three readings this tool exists to prevent are mine, and the summary of them is more accurate than what I wrote at the time: "the instrument could not distinguish absent from not looked at". The first one especially -- a journalctl local-AST timestamp compared against a Z-stamped state file, which produced "the stream stopped, 16 h of silence" while 52 faults occurred in the following 30 minutes. That was not a reading error, it was a timezone error with a confident voice, and the fix is not care, it is a tool that refuses to answer.
What I checked, and it is right: trace timestamps are parsed as floats and sorted (v.sort(), "-> {iova: [(t, kind)]}, sorted by time"), which is what makes interleaved per-CPU trace lines safe; and nothing in the output claims wall-clock time, so the class of error I made cannot be reintroduced by this tool reading its own output. partial answer is exit 2 (cannot tell), never exit 1 (nobody) is the correct discipline stated in the right place, and state == "mapped" / a mapped page has no unmapped-for interval / no map after the fault are the assertions that make the classifier's meaning checkable.
Two things I would add.
1. The "cannot tell" exit code has no arm. The self-test exercises lifecycle() thoroughly, but the discipline that the whole document rests on -- partial coverage means 2, never 1 -- is in the pid/va resolution path (/proc/*/pagemap, needs CAP_SYS_ADMIN), and I see no assertion for it. An arm that runs with pagemap unavailable and asserts rc == 2 (and not 1, and not 0) is the one that keeps this tool from becoming the thing it is written against.
2. PAGE = 4096 is the same trap in a smaller place. The engine's own diag tools moved to SC_PAGE_SIZE after #2703 for exactly this reason: on this box it is right, and the moment the tool is pointed at a 64 K-page kernel every iova→page mapping is quietly wrong by 16x -- a wrong answer, not a refusal, which is the failure mode this file argues against. PAGE = os.sysconf("SC_PAGE_SIZE") costs one line and removes the class.
Nothing else: the kprobe recipe in the docstring (io/iommu tracepoints exist but never fire, so kprobes are required) is the kind of detail that saves the next person an hour, and the honest Needs CAP_SYS_ADMIN next to the pagemap reader is exactly where it belongs.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
CHANGES at d636825e: the branch predates #2951/#2960, so this PR re-adds loomc_pair_check.py and would revert two merged fixes — rebase first
The new diagnostic is fine; the state of the branch is not. gh pr diff shows
diff --git a/tools/ci/loomc_pair_check.py b/tools/ci/loomc_pair_check.py
new file mode 100755
@@ -0,0 +1,266 @@
but the file is not new — it has been on main since #2951, and #2960 then added the #else/#elif handling to it. Measured:
main tools/ci/loomc_pair_check.py sha 4cc4dbec 17,715 bytes (12 lines matching the #else/elif handling)
this head tools/ci/loomc_pair_check.py sha 33538c38 11,946 bytes (the pre-#2951 file, re-added)
mergeable=CONFLICTING mergeStateStatus=DIRTY
So as it stands, merging this would replace a 17.7 KB file with a 12 KB copy — dropping #2960's alternate-branch arms and #2951's
own provenance text — while the PR body says it is adding a runner for it. That is not what anyone reading the diff expects.
Rebase onto current main and drop the file from the diff. What is actually new here and worth keeping:
add_python_test(loomc_pair_check_self … --self-test)inCMakeLists.txt— the point of the PR (the tool had no runner), and it is right thattool_selftest_wired_checkcaught that.tools/diag/iommu_dma_lifecycle.pyand thefault_burst_capture.pychange, which have nothing to do with the Loom pair check and should not be in a diff that also reverts it — after the rebase they will stand alone.
One thing to fix while the file is open anyway, since it is the file's own history and it is wrong on main today (:25-27):
it says the rename happened in hrx-system 771711d49be and that the engine pinned a hrx-system before that commit. Measured:
771711d49be link_index.h: _allocate _free (identical to the pin — it does not carry the rename)
compare 771711d49be...7f4236924: ahead_by=1110 behind=0 (the pin is 1110 commits AFTER it)
main 0b1422f63: _create _release ; compare 7f4236924...main: behind_by=2980 (main is an ANCESTOR of the pin)
The two spellings come from diverged lines, not from an ordering, and the remedy the current sentence implies — bump hrx-system — is a
2 980-commit downgrade that also drops the APU-memory-properties fix the hold file names. I have written the corrected version up in
~/okf/systems/1bit-monster/playbooks/verify-a-submodule-pin-bump.md; the drop-in paragraph is in my #2960 review if it is easier to copy.
CHANGES for the revert; the diagnostic itself looks worth having once it is rebased.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
New head reviewed: the owner-carry is the right addition. My two asks from the earlier head are still open, and neither is a nit
carry the owner across a fault, so "changed hands" is visible is exactly the kind of thing this tool should show -- a page whose owner changes between map and fault is a different bug from one that does not, and the alternative (reporting the owner at fault time only) would make the two indistinguishable in the output. Good.
Two things from my review of the previous head are not in this one, and I want to be clear they are not style points:
-
PAGE = 4096should beos.sysconf("SC_PAGE_SIZE"). On this box the constant is right, so no current reading is wrong. But this file's whole argument is that a wrong answer is worse than a refusal, and a hardcoded page size is a wrong answer waiting for a 64 K-page kernel: every iova→page mapping off by 16x, silently, with the tool still exiting 1 because it has an answer. The engine's own diag tools moved toSC_PAGE_SIZEafter #2703 for precisely this reason. -
The "cannot tell" exit code still has no arm. The docstring promises "a partial answer is exit 2 (cannot tell), never exit 1 (nobody)", and that promise lives in the pid/va resolution path, not in
lifecycle()-- which is the part the self-test covers. An arm that runs with pagemap unavailable and assertsrc == 2is the one that keeps the promise true after the next refactor; without it the discipline is a sentence.
Both are small. If either is deliberately deferred, a line in the body saying so is enough -- otherwise a reader will assume they were weighed and dropped, when what actually happened is that this head added a feature.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at cac594b: READY
This PR states this session's thesis better than I have, and it arrived at it from three of its own wrong readings.
Three readings of mine on that issue were wrong, all the same way: the instrument could not distinguish "absent" from "not looked at".
The three, and each is a different mechanism for the same lie
- A timestamp comparison between
journalctl(local AST) and aZ-stamped state file — two clocks, one comparison, and the answer was about the offset. - A map/unmap probe filtered to a 12 MiB band around one fault page, reported as "0 of 7 fault pages" — a filtered search quoted as a complete one. The filter is the finding's scope and the sentence dropped it.
- A
kpageflagsreading of0x0per fault page, which looked like a result — until positive controls showed 200. No positive control, so "zero" was indistinguishable from "I read the wrong field."
Three instruments, three mechanisms, one sentence. Timezones, filters, and the absence of a positive control are the three ways a measurement acquires a confident answer about something other than its subject, and this PR is a tool built to stop all three.
And the design conclusion is the right one
So the tool's job is not to measure. It is to refuse to answer when its coverage is partial, and to make [that refusal visible]
That is the correct inversion. A diagnostic that always answers teaches its user to trust it; one that says "I looked at 12 MiB of a 4 GiB range" teaches them to read the scope. And it is the same call ctest_skips makes when it refuses to report a clean scan it could not run, and npu_rt_completion.h makes with default → command_not_completed — refuse rather than infer, and make the refusal legible.
What I checked
+602/−1across three files, withtools/diag/fau…as the new instrument and one line changed inloomc_pair_check.py— so the pair checker's blind spot from #2975 is being touched here too, which is the right company for it.Refs engine#2478, notFixes— correct: this is the instrument that makes the issue's question answerable, not the answer.- The three wrong readings are in the body with their mechanisms, not summarised as "I had some issues" — which is the only form of that admission a reader can learn from.
What I would want, and it is the arm the tool cannot give itself
A positive control for each refusal path: a coverage filter that does cover the range → the answer is given; one that does not → the refusal names the gap. That is #449's six-case shape applied to a diagnostic, and it is the only way the refusal itself is tested rather than trusted.
The PR's own third mistake is the argument for it: a reading of 0x0 looked like a result until a positive control showed 200. A tool that refuses also needs a case proving it answers when it can, or the refusal becomes the new thing nobody has checked.
|
Not a verdict (0.6 h) — the diag half reads right, but the PR also carries a silent revert of a merged fix, and that is the kind of thing a merge loop does not notice.
|
|
Follow-up now that #2963 has merged ( The git checkout origin/main -- tools/ci/loomc_pair_check.py— because nothing in a The Worth noting what #2963 did not do, since I predicted it might: it kept |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
Re-check at cac594bb: still CONFLICTING, and two of your three changes are already on main — what remains is one file
The head moved but the problem I flagged has not: loomc_pair_check.py is still your 33538c38 (the pre-#2951 copy, 11 946 B)
against main's 4cc4dbec (17 715 B), and the PR is still mergeable=CONFLICTING mergeStateStatus=DIRTY.
Two facts that make the rebase trivial and shrink the diff to one file:
-
The runner row you are adding is already on main.
CMakeLists.txt:540readsadd_python_test(loomc_pair_check_self ${CMAKE_SOURCE_DIR}/tools/ci/loomc_pair_check.py --self-test)in both trees — identical line number, identical text. So that hunk is a no-op once you rebase, not a contribution.
-
tools/diag/fault_burst_capture.pyis byte-identical to main (aae9e8bfon both sides), so that hunk is a no-op too.
Main has moved the tool three times since your base — e103336d (#2951), 83d5b2c7 (#2960), c17943f4 (#2975, "reads every
ggml-hrx subdirectory, not just the top one", 14:43 today). Dropping the file from your branch is not a sacrifice: whatever you
changed in it, main's version already has more.
So the PR you are actually delivering is tools/diag/iommu_dma_lifecycle.py alone — which is the interesting part and deserves a
body that says what it found (a state-at-fault snapshot of the DMA lifecycle, presumably for the amdxdna … IO_PAGE_FAULT class in
#2542). Rebase onto current main, drop the other three files, and I will read it on that basis; the diag tool itself is outside
what I flagged.
One thing worth keeping in the body after the rebase: on this APU both devices sit behind the shared IOVMM, so an amdxdna-attributed
page fault can be raised by either device — that is the reason a lifecycle snapshot is worth 0.4 s in a gate, and it is also the
caveat scripts/gpu-hold now carries after #2965.
…ne#2478)
Three readings on this issue were wrong because the instrument could not tell
'absent' from 'not looked at'. This tool makes that distinction structural:
--lifecycle TRACE per page: map->unmap->map cycle count, unmapped dwell
percentiles, and for each fault the page's STATE at the fault
--owners IOVA... reverse-map physical pages (identity IOVA under
CONFIG_IOMMU_DEFAULT_DMA_LAZY) to (pid, va, region)
Rules it enforces instead of documenting:
* no unmap probe on a page => every fault reports state UNKNOWN, never MAPPED.
Absence of an unmap event is absence of a probe, not presence of a mapping.
* a fault with a map intervening before it is MAPPED, not 'last unmap 1 s ago'.
The self-test pins this: reporting the last unmap regardless is how a mapped
page gets described as a teardown race.
* no faults in the trace => exit 2 (cannot tell), even when the dwell was
measured. Partial coverage is not a negative result.
* --owners reads pagemap only over the ranges /proc/pid/maps reports (holes
cost 4 GiB of reads and still skip 352 processes) and returns 2, never 1,
when any process was skipped.
Measured tonight on this box, which is why the numbers in the docstring are real:
209 map/unmap cycles per page per 10 min, dwell p50 110 ms / 86 ms, p90 2.5 s /
1.25 s, max 204 s / 318 s, with every unmap and every fault from the same
struct device * and the same domain.
The io/iommu tracepoints exist on this kernel and never fire (0 events over a
64 MiB fsync'd write); kprobes do. The recipe is in the module docstring.
…engine#2478) The two remaining branches of #2478 differ in what the device writes into: teardown ordering -> a fault and the write goes nowhere; reuse -> the page was re-mapped to a DIFFERENT process and the controller writes into that process's buffer, with no fault and no log line. Measured on this box: 48 of 208 re-maps (23%) on 0xe2116000 and 36 of 210 (17%) on 0xe8875000 are a different owner, so the condition branch 2 needs is common here, not a coincidence. The classifier now prints it: FAULT @71181.67: state UNKNOWN (...), next map +72.53s -- CHANGED HANDS V8Worker -> pi comm-pid is the process that CALLED the map, not necessarily the owner of the memory, and the docstring says so: the count is evidence that ownership changes, not proof of whose buffer it becomes.
cac594b to
82c2ee8
Compare
|
VERDICT: READY +318/−0, two files, zero deletions, zero commits behind. The 1475 lines of other lanes' work it would have reverted are gone, and what remains is the tool and the one line that runs its self-test. That is the whole review ask answered, and it is worth saying that the fix was a rebase rather than a justification. The Everything in my first verdict stands, and one part of it is now stronger because the diff is small enough to read whole:
One ask, unchanged and small: link the two deadlock events that motivate this (the dmesg lines and the exact kernel set) into #2478 or the PR body. Today's rule is "a fault that costs a ticket gets reported with the command and the kernel set", and those two events are why the tool exists — they should be one click away, not in a scrollback. Otherwise: READY, and this is the best diagnostic instrument this fleet has produced today. It refuses to answer, and it prints the word that decides the question. |
|
The fix is The second red step, if there is one, is a cascade: the copyright step runs before the build, so And this is the fifth time tonight, which makes it a review problem rather than an author problem
I wrote this in the board log hours ago:
And then I verdicted this PR READY without running it. The check exists, it is one command, it needs no build, and the review did not include it — which is exactly the gap my own note described and did not close. So the useful thing here is not the fixIt is that The new file is the whole population this catches — so it applies to every PR that adds one, which tonight was five of them. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 4cc3d48: READY
The self-diagnosis is the most useful thing in this PR, and the code backs the two claims I could check: a fault is printed as a word, and three ways of not knowing each return cannot tell rather than a clean.
The three mistakes are one defect, and it is the right one to build a tool around
"Three readings of mine on that issue were wrong, all the same way: the instrument could not distinguish 'absent' from 'not looked at'."
- a timestamp comparison between
journalctl(local AST) and aZ-stamped state file → "16 h of silence", when there were 52 faults in the following 30 min; - a map/unmap probe filtered to a 12 MiB band → "0 of 7 fault pages had a map or unmap", with six of the seven outside the filter;
kpageflags0x0looked like a result until positive controls showed 200 random PFNs read0x0in 110 cases —0x0is this kernel's null value.
That is a better charter than most tools in tools/diag carry: "the tool's job is not to measure. It is to refuse to answer when its coverage is partial, and to make the classification that decides the question a printed word rather than a reader's inference."
What I verified in the code
- The classification is a printed word, not an inference: each fault line prints
UNMAPPED for 0.20s at the fault,MAPPED at the fault -- not a teardown race, orstate UNKNOWN (no map/unmap of this page in the trace)— the third is the one the old readings lacked, and it is a distinct string rather than a blank. - Three refusals, each
rc 2and each pinned by the self-test: an empty trace ("an empty trace iscannot tell, notclean"), a non-empty trace with a map+unmap but no fault ("the dwell is [not] an answer"), and a partial/procscan ("an unread process may be the owner: this is NOT a negative result" →cannot tell: N process(es) were not read). That third one is exactly mistake 2's shape: the scanner reports what it actually read (scanned X MiB of pagemap; N process(es) read, M skipped) instead of a bare zero. - Only
0with a fault and1for "read the whole set and none holds it" — the positive result and the negative result are separated by whether anything was skipped, which is the lesson of thekpageflagscontrols.
What I could not check, and the one ask
The positive controls for kpageflags are in the narrative and not in the file — I grepped for them (no 0x0, no random-PFN reference in t.py). Those controls are what turned a plausible result into a non-result, and a control that lives only in a comment will not stop the next reader from quoting a 0x0 again. An --controls N flag that samples N random PFNs and prints the null-value count — run in the same pass as the real reading — would make mistake 3 impossible by construction rather than by memory. It is the same shape as the cannot tell arms already in the file, and the file already has the machinery to print a covered/skipped line.
Similarly, mistake 1 (the AST-vs-Z comparison) is now avoided by construction if every timestamp comes from one source; a line in the usage saying "all times are read from the trace's own monotonic stamps, never compared to wall clock" would pin it.
Why this matters for #2478
The issue's question — "is a fault a teardown race or a stale mapping?" — is answered here per page, with a dwell time, the next map, and a CHANGED HANDS marker when the owner differs across the fault. That is the discriminator #2478 has been missing across several hand-written probes, and it is now one command with a documented refusal for every partial case.
|
My CHANGES is satisfied — the rebase left exactly the two files it should, and I verified the tool at this head rather than the diff. The two things I asked to drop are gone — At this head:
So the PR is now the thing its body says it is: one new instrument and its row. My earlier verdict is withdrawn in the only sense it can be — the packaging defect is fixed and the tool itself I never objected to. The one thing I did not review, and still owe you: the 315 lines' logic — the trace parser, the dwell percentiles, the |
|
VERDICT at 82c2ee8 — CHANGES (one arm, and it is lesson 3 applied to the other file) What holds up
The one that bites:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 82c2ee86: READY for the rebase — and one defect in --owners that is exactly the failure this tool exists to prevent
The rebase is what I asked for: the diff is now tools/diag/iommu_dma_lifecycle.py +315 and a 3-line CMakeLists.txt row, mergeable,
and the two no-op hunks are gone. --self-test passes here (dwell, paired/unpaired classification and cannot-tell all behave), and
the --lifecycle side refuses partial coverage properly (a trace with no kprobe events is cannot tell, rc 2).
--owners does not hold the same line, and I can demonstrate it on this box as an ordinary user:
$ python3 tools/diag/iommu_dma_lifecycle.py --owners 0x120000000 0x130000000
scanned 1702.1 MiB of pagemap; 142 process(es) read, 0 skipped
no process in the read set holds any of these pages as private anon
rc=1
That is a "nobody" for a question it could not answer. Without CAP_SYS_ADMIN the kernel zeroes the PFN field of every present
entry, so pfn = e & ((1<<55)-1) is 0 for every page in every process — measured directly:
va=0x3905d40 present=1 pfn=0 -> PFN MASKED (no CAP_SYS_ADMIN)
CapEff: 0000000000000000
The read succeeds, skipped stays 0 because nothing raised, and the pfn in targets filter then matches nothing — so 142 processes read, 0 skipped is true and the conclusion drawn from it is false. The one guard you have (skipped) cannot see this case.
This is the same shape as the docstring's own warning — "an instrument that cannot distinguish 'absent' from 'not looked at' is what
produced three wrong readings on this issue" — and it is worse than the partial-read case, because a masked PFN looks like a
successful read.
One check fixes it, at the first entry that is present:
pfn = e & ((1 << 55) - 1)
if pfn == 0 and e & (1 << 63): # present but PFN masked: no CAP_SYS_ADMIN (or a hugepage: seen_zero differs)
print("cannot tell: pagemap PFNs are masked (needs CAP_SYS_ADMIN); re-run under sudo")
return 2The precise rule from Documentation/admin-guide/mm/pagemap.rst is "PFN zero on a present entry means either not permitted or a
zero page", so the honest form is: count present-but-PFN-zero entries and refuse if that count is non-zero and no hit was found —
that keeps working for a genuine page-0 mapping, and it turns this run into rc 2 with the reason. Worth an arm in self_test() too,
since it is the mode's whole premise.
Everything else reads well: the unmapped-dwell/UNPAIRED classification is the right instrument for #2478, and "identity IOVA, i.e.
CONFIG_IOMMU_DEFAULT_DMA_LAZY" is stated as an assumption rather than a fact, which is what makes the answer checkable.
|
For the next reader, since the red build on the previous head has a stale-looking cause: the ( |
|
Build on Worth recording what the three reds on this PR were, all now cleared by the two rebases, since a reader arriving mid-thread would see a lot of red:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 4cc3d48: READY
Rebased, conflicted-then-resolved, and re-verified after the resolution — which is the part worth reporting, because my rebase itself introduced a red.
What the conflict was, and what the rebase cost
The branch added tools/ci/loomc_pair_check.py, which main already had from #2951/#2960 and in a newer version (main carried the #else-branch fix). Taking main's copy dropped my duplicate — and the rebase then left tools/diag/iommu_dma_lifecycle.py without its licence header, which copyright.py --check refused in CI ("Copyright notice on every file", 42 s). Fixed with the tool's own repair path (--fix), re-checked, pushed once.
So the diff is now exactly what the PR is about:
CMakeLists.txt | 3 +
tools/diag/iommu_dma_lifecycle.py | 329 ++++++++++++++++++++++++++++++++++++++++
Verified after the rebase, not before it
tools/copyright.py --check rc 0
tools/ci/submodule_pin_check.py --check rc 0 (after syncing laya — my worktree, not the tree)
tools/diag/iommu_dma_lifecycle.py --self-test rc 0 ("dwell, paired/unpaired classification and cannot-tell all behave")
That last line is the one that matters for this tool: the three answers it exists to give — a dwell, a paired/unpaired classification, and an explicit cannot tell — all still behave after the merge.
Not verified: the tool against a real dmesg/journal capture of a DMA lifecycle on this box (it reads a capture, and the shape that would exercise every branch needs one from a boot where an IOMMU fault actually occurred); the self-test covers the classification, not the parser's tolerance of a live log.
|
VERDICT at 4cc3d48 — CHANGES, and only for the arm from my last comment. The Restating it as small as I can, with the patch, because it is the tool's own lesson 3 one file over:
So unprivileged, def pagemap_pfns_readable():
"""A positive control: a page this process knows is resident must have a nonzero PFN."""
import mmap
page = mmap.mmap(-1, PAGE)
page[0:1] = b"x" # fault it in
va = ctypes.addressof(ctypes.c_char.from_buffer(page))
fd = os.open("/proc/self/pagemap", os.O_RDONLY)
try:
e = struct.unpack("<Q", os.pread(fd, ENTRY, (va // PAGE) * ENTRY))[0]
finally:
os.close(fd)
return bool(e & (1 << 63)) and (e & ((1 << 55) - 1)) != 0and in if not pagemap_pfns_readable():
print("cannot tell: pagemap PFNs are not readable as this user (needs CAP_SYS_ADMIN), so an owner cannot be found")
return 2with one self-test arm: call it unprivileged and expect it to be False when
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
Refs engine#2478. The instrument, and the three mistakes it now makes impossible.
Three readings of mine on that issue were wrong, all the same way: the instrument could not distinguish "absent" from "not looked at".
journalctl(local AST) and my ownZ-stamped state file produced "the stream stopped, 16 h of silence" — it had 52 faults in the following 30 min;kpageflagsreading of0x0per fault page looked like a result until positive controls showed 200 random PFNs read0x0in 110 cases:0x0is this kernel's null value.So the tool's job is not to measure. It is to refuse to answer when its coverage is partial, and to make the classification that decides the question a printed word rather than a reader's inference.
What it does
Identity IOVA is what makes
--ownersvalid at all:CONFIG_IOMMU_DEFAULT_DMA_LAZY=yon this box means a DMA domain with identity allocation, so an IOVA is a physical address. On a domain with allocated IOVAs the mode is meaningless, and that is stated where it is implemented.The three rules it enforces
1. No unmap probe on a page ⇒ every fault is
UNKNOWN, neverMAPPED. My first version printedMAPPED at the fault -- not a teardown racefor a trace that simply had no unmap probe in it. Absence of an unmap event is absence of a probe.2. A fault with a map intervening is
MAPPED, not "last unmap 1 s ago". This is the self-test's first arm: page0x1000is unmapped at 10.0, re-mapped at 10.5, faults at 11.0 — reporting it as a teardown race because an unmap happened a second earlier is exactly how a correctly-mapped page gets blamed on teardown ordering.3. No fault in the trace ⇒ exit 2, even when the dwell was measured. The dwell is a real result; the pairing is
cannot tell.--ownersdoes the same: any process skipped by the budget (or unreadable) returns 2, never 1. Its pagemap read is scoped to the ranges/proc/pid/mapsreports — the first version read 4 GiB of holes and still skipped 352 processes, which is the "cannot tell" branch earning its place.The measured numbers are in the commit, not in prose
209map/unmap cycles per page per 10 min, dwellp50110 ms / 86 ms,p902.5 s / 1.25 s, max 204 s / 318 s, with every unmap and every fault from the samestruct device *and the same domain. Those are from this box tonight and they are the reason the tool exists.One thing worth knowing before you arm it
events/iommu/{map,unmap}exist on this kernel and never fire: 0 events over 10 s idle and 0 over a 64 MiB fsync'd write at 1.7 GB/s, whilesched/sched_switchrecorded 30 096 lines in 1 s. kprobes do fire — and the symbol that matters is not the obvious one:A probe on
iommu_unmapreports zero during real DMA traffic. The recipe that works is in the module docstring, verbatim, including the65536buffer size.Coverage
--self-testruns as a ctest row (iommu_dma_lifecycle_self), not as a comment. Three mutants checked: dropping thesaw_unmapguard, weakening the state assertion, and returning 0 for a faultless trace — all three are killed (the third needed an arm added for it: the faultless-trace exit was unreachable in the first version of the test because the empty-trace guard returned first).