Repository navigation
fix(selene): preserve DMA, RDMA, and shared-region lifetimes across cancel, close, and scatter - #609
Merged
Conversation
yatesdr
force-pushed
the
fix/selene-dma-lifetime-safety
branch
2 times, most recently
from
November 29, 2026 17:26
a99d917 to
565e0df
Compare
Active GPU DMA, host compression, NIC RDMA, and concurrent data-channel workers can access mapped host or shared-memory ranges across close, panic unwind, quarantine, and multi-rank scatter paths. Unmapping a region before every local copier, RDMA queue pair, and compression worker has drained causes use-after-unmap, and constructing overlapping `&mut [u8]` slices in `LocalRegions` is undefined behavior under concurrent readers or multi-rank writes. - Declare `transfers` before `core`/`pool` in `MemoryStore` and `disk_store::Resources`, close both tiers in `CompositeStore::close`, guard `AsyncCompressor`'s active count with an RAII drop guard, and leak the slab pool and report an error if compression does not finish before `MemoryStore::close` (`selene/src/memory.rs`, `selene/src/disk_store.rs`, `selene/src/composite.rs`). - Retain `sess.regions` and `Attachment::Shm` in `Engine::quarantine`, retain `self.shared` in `Agent::quarantine`, and invoke `engine.quarantine()` when `conn::shutdown` fails to drain (`selene/src/pool/engine/mod.rs`, `selene/src/pool/conn.rs`, `selene/src/pool/agent.rs`). - Wrap `Staging.region` in `Arc<Region>` and retain it inside `rdma::Device` so quarantined RDMA queue pairs keep their registered staging mapped (`selene/src/pool/rdma.rs`, `selene/src/pool/net.rs`). - Add `LocalRegions::bytes_read`, `LocalRegions::ptr_mut`, and `SliceLayout::scatter_disjoint` so concurrent read paths borrow `&[u8]` and multi-rank data-channel scatter writes only each rank's disjoint byte ranges without aliasing `&mut [u8]` (`selene/src/shared/slice.rs`, `selene-manager/src/regions.rs`, `selene-manager/src/pool/pass.rs`, `selene-manager/src/data/channel.rs`). - Attach `ReadAhead`'s overlapped file handle to its IOCP queue on Windows (`selene/src/disk.rs`). Every affected teardown, quarantine, RDMA, and concurrent region access path now preserves backing mappings and disjoint ownership until all DMA, RDMA, and worker accesses finish. Validated on Linux (rebased onto post-NVIDIA#607 main `5df8edd3c`), GB10, and SM120 hardware across `selene`, `selene-manager`, and `helios offload::`. Signed-off-by: yatesdr <6937857+yatesdr@users.noreply.github.com> Design-Signed-Off-By: yatesdr; design-review=2e5b
yatesdr
force-pushed
the
fix/selene-dma-lifetime-safety
branch
from
November 29, 2026 17:27
565e0df to
304dd3a
Compare
Collaborator
|
A case file has been opened for 609. Future reviews will auto-run 90 minutes after code updates are pushed.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this change is needed
Active GPU DMA, host compression workers, NIC RDMA queue pairs, and concurrent data-channel workers can access mapped host or shared-memory ranges across close, panic unwind, quarantine, and multi-rank scatter paths. Before this change:
MemoryStoreanddisk_store::Resourcesdropped their slab pools before joining transfer/compression threads,CompositeStore::closeshort-circuited without closingmemorywhendisk.close()failed, andAsyncCompressorcould leak its active counter on panic or leave its slab pool unmapped after a close timeout.Engine::quarantine,Agent::quarantine, andconn::shutdowncould drop mapped shared/session regions while an un-drained peer or copier still referenced them, andrdma::Devicedid not retain the stagingRegionfor quarantined queue pairs.LocalRegionsconstructed overlapping&mut [u8]slices across concurrent read and multi-rank scatter paths (undefined behavior in Rust).ReadAhead::startopened an overlapped file handle without attaching it to its IOCP queue.The minimal fix is to make every teardown, quarantine, RDMA, and shared-region access preserve backing mappings and disjoint byte ownership directly at each boundary, without changing wire protocols or runtime architecture.
What changed
selene/src/memory.rs,selene/src/disk_store.rs,selene/src/composite.rs,selene/src/offload/tests.rs): Declaretransfersbeforecore/poolinMemoryStoreanddisk_store::Resources; close bothdiskandmemoryinCompositeStore::close; guardAsyncCompressor's active count with an RAII drop guard; leak the slab pool, forget the compressor, and return an error if compression does not finish beforeMemoryStore::close.selene/src/pool/engine/mod.rs,selene/src/pool/conn.rs,selene/src/pool/agent.rs,selene/src/pool/rdma.rs,selene/src/pool/net.rs): Retainsess.regionsandAttachment::ShminEngine::quarantine, retainself.sharedinAgent::quarantine, invokeengine.quarantine()whenconn::shutdowntimes out, and wrapStaging.regioninArc<Region>retained byrdma::Device.selene/src/shared/slice.rs,selene-manager/src/regions.rs,selene-manager/src/pool/pass.rs,selene-manager/src/data/channel.rs): AddLocalRegions::bytes_read(&[u8]),LocalRegions::ptr_mut, andSliceLayout::scatter_disjointso concurrent readers borrow&[u8]and multi-rank scatter writes only each rank's disjoint byte ranges without aliasing&mut [u8].selene/src/disk.rs): AttachReadAhead's overlapped file handle to its IOCP queue under#[cfg(windows)].mid_session_quarantine_retains_active_session_and_attachment_regions,scatter_disjoint_matches_gather_across_ranks, andbytes_read_allows_overlapping_shared_views.Expected benefit and measured result
Every affected teardown, quarantine, RDMA, and concurrent shared-region access path now keeps backing mappings alive and preserves disjoint ownership until all GPU DMA, NIC RDMA, and worker accesses settle, with zero latency or parity regression on SM120 and SM121 serving workloads.
Supporting evidence
#607main(5df8edd3c):RUSTFLAGS="-D warnings" cargo check --locked --manifest-path selene/Cargo.toml --all-targets --features codec,rdmaandselene-manager --lib --bins: passed with 0 warnings.cargo test --locked --release --manifest-path selene/Cargo.toml --features codec --lib: 541/541 passed.FLARE_RUN_CUDA_TESTS=1SM120 4× RTX PRO 6000 (cn5, withkv_codec_gpu-sm_120a): 28/28helios::offload::CUDA tests passed (including multi-GPUsplit_poolsand GPU codec tests).flare run+selene-managerqualification acrossDeepSeek-V4.1-Flash-1017TP4,GLM-5.3-FlashTP2 & TP4 (off/cpu/gpu),Qwen3.8-Flash-NextTP1 & TP2 on SM120 (cn5), and multi-host TP2/TP4 (--roce-ring) on GB10 (cn6–cn9): 0 panics, 0 quarantined bytes, bit-exactpos0parity across all phases, and cleanSIGTERMshutdowns.#[cfg(windows)]IOCPReadAhead::startattach was reviewed against the existing Windows IOCP attach contract indisk.rsbut not compiled or executed on Windows; live hardware qualification ran against the combined 4-PR stack before rebasing onto#496/#497/#607, and CPU tests were re-run after rebasing onto5df8edd3c.Discord: D-Rock