Repository navigation
docs: who makes the provider's mapping, and the trap that makes it silent (Refs #753) - #1424
Conversation
…lent (Refs #753) #1317's review left one nit: hybrid.md said the provider writes through "its own mapping" while zero-copy.md said a driver-made mapping poisons the submission, and the pair is only consistent once a reader works out that the distinction is *who made the mapping*. Both pages now say that outright. The cross-process measurement behind the writer added a second, sharper fact, so it goes in the same paragraph: a provider can mmap the dma-buf fd it is handed (measured; it aliases the decoder's pages), but that mapping is LAZY. A device write into pages the provider has not touched is dropped with no error, no fault and a completed launch -- the write looks like it never happened, and the first cross-process run blamed the import for exactly that. The contract now says: touch the whole region before the device writes it. No kernel internals; the design, the measurement and the traps are in the private tree (npu-kernels#29, #30). Refs #753
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at e0abe565.
The trap it adds is real and the two pages agree about it — I checked that specifically, because the same paragraph now lives in hybrid.md and
zero-copy.md and drift between them would be worse than neither:
hybrid.md lazy-mapping trap described, cites engine#753 (measured both) and engine#812 (the poisoning route)
zero-copy.md same trap, same two issues
A device DMA into pages the process has not faulted in is dropped with no error and no fault, so the write "looks like it never happened" — that
is exactly the failure mode, and pairing it with the #812 rule (never write through a driver-made mapping of the imported buffer) is right: one
rule says which mapping, the other says prepare it.
One addition that would make it actionable rather than correct: "touch the whole region before the device writes it" leaves the obvious
wrong implementation available — a reader can touch one byte and believe they are done, because the pages after it are not faulted. Naming the
per-page shape ("one byte per page, e.g. for (p = buf; p < buf+len; p += 4096) *p = *p;", or madvise/MAP_POPULATE if the mapping is made
for this purpose) turns a rule into a recipe. Non-blocking; the paragraph is true as written and the reader who knows mmap will implement it
correctly.
Also good: "the engine side of this contract needs no change for it" with the three touchpoints named (?action=share, ?action=adopt,
llama_kv_cells_adopt) — that is the sentence that stops someone opening a PR against the engine for a provider-side trap.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
The review is right that "touch the whole region" leaves the obvious wrong implementation available -- touch one byte and believe you are done, because the pages after it are not faulted. Both pages now name the per-page shape (one byte per page, MAP_POPULATE, or MADV_WILLNEED) and say outright that a single byte is not enough, which is the mistake that cost the first cross-process run. Refs #753
|
Taken, at head Both pages now give the recipe rather than the rule: one byte per page ( |
|
Preparing review... |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at f9d973dd.
The per-page recipe I suggested is in, in both pages, and worded better than the suggestion:
hybrid.md "fault the whole region in … one byte per page is enough (for (p = buf; p < buf + len; p += 4096) *p = *p;),
or mmap it with MAP_POPULATE, or madvise(MADV_WILLNEED) … touching a single byte of the region is *not* enough,
and looks identical to having done the right thing"
zero-copy.md "every page of the region has to be faulted first — one byte per page, or MAP_POPULATE / MADV_WILLNEED;
touching one byte of the region [is not enough]"
The clause "looks identical to having done the right thing" is the part that earns its place: it is the reason the trap survives code review,
and it is the same failure the measurement tool had to be fixed for (#30's :195, where the 4 KiB marker was exactly that "touching one byte"
shape and std::memset(mine, 0, REGION_BYTES) was the actual fix). Naming both the recipe and the false-confidence mode means the next reader
cannot implement the wrong half of it and believe they are done.
Both pages still agree with each other and with #753/#812; nothing else moved.
What this is
Two things, both discovered after #1317 merged, both fitting in the same two paragraphs:
hybrid.mdsaid the provider writes through "its own mapping" andzero-copy.mdsaid a driver-made mapping poisons the submission; the pair only reads consistently once a readerworks out that the distinction is who made the mapping. Both pages now say so.
mmapthe dma-buf fd it is handed and gets the decoder's pages (measured: the mapping aliases the exporter's,checked with a sentinel written before the fork). But that mapping is lazy: a device write into pages the
provider has not touched is dropped with no error, no fault, and a completed launch. My first cross-process
run touched only the first 4 KiB, saw the K plane written and V zero, and blamed the import for it; touching the
whole region through the mapping first made all four planes bit-exact. The contract now says: touch the whole
region before the device writes it.
Engine#753's writer is measured bit-exact both in-process and across a process boundary (
SCM_RIGHTS, the shapethis route uses): 262 144 B of cache, decoder's layout, read back through the decoder's own mapping. Details and
the three traps stay in the private tree (npu-kernels#29, npu-kernels#30).
Docs only: no engine behaviour changes, nothing to gate.
copyright.py --checkclean.Refs #753