Skip to content

fix(selene): preserve DMA, RDMA, and shared-region lifetimes across cancel, close, and scatter - #609

Merged
yatesdr merged 1 commit into
NVIDIA:mainfrom
yatesdr:fix/selene-dma-lifetime-safety
Nov 29, 2026
Merged

yatesdr merged 1 commit into
NVIDIA:mainfrom
yatesdr:fix/selene-dma-lifetime-safety

Conversation

@yatesdr

@yatesdr yatesdr commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

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:

  • MemoryStore and disk_store::Resources dropped their slab pools before joining transfer/compression threads, CompositeStore::close short-circuited without closing memory when disk.close() failed, and AsyncCompressor could leak its active counter on panic or leave its slab pool unmapped after a close timeout.
  • Engine::quarantine, Agent::quarantine, and conn::shutdown could drop mapped shared/session regions while an un-drained peer or copier still referenced them, and rdma::Device did not retain the staging Region for quarantined queue pairs.
  • LocalRegions constructed overlapping &mut [u8] slices across concurrent read and multi-rank scatter paths (undefined behavior in Rust).
  • On Windows, ReadAhead::start opened 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

  • Store/transfer teardown & compression lifetime (selene/src/memory.rs, selene/src/disk_store.rs, selene/src/composite.rs, selene/src/offload/tests.rs): Declare transfers before core/pool in MemoryStore and disk_store::Resources; close both disk and memory in CompositeStore::close; guard AsyncCompressor's active count with an RAII drop guard; leak the slab pool, forget the compressor, and return an error if compression does not finish before MemoryStore::close.
  • Quarantine & RDMA staging retention (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): Retain sess.regions and Attachment::Shm in Engine::quarantine, retain self.shared in Agent::quarantine, invoke engine.quarantine() when conn::shutdown times out, and wrap Staging.region in Arc<Region> retained by rdma::Device.
  • Disjoint shared-region access (selene/src/shared/slice.rs, selene-manager/src/regions.rs, selene-manager/src/pool/pass.rs, selene-manager/src/data/channel.rs): Add LocalRegions::bytes_read (&[u8]), LocalRegions::ptr_mut, and SliceLayout::scatter_disjoint so concurrent readers borrow &[u8] and multi-rank scatter writes only each rank's disjoint byte ranges without aliasing &mut [u8].
  • Windows IOCP attach (selene/src/disk.rs): Attach ReadAhead's overlapped file handle to its IOCP queue under #[cfg(windows)].
  • Unit tests: Added mid_session_quarantine_retains_active_session_and_attachment_regions, scatter_disjoint_matches_gather_across_ranks, and bytes_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

  • Standalone branch rebased onto post-#607 main (5df8edd3c):
    • RUSTFLAGS="-D warnings" cargo check --locked --manifest-path selene/Cargo.toml --all-targets --features codec,rdma and selene-manager --lib --bins: passed with 0 warnings.
    • cargo test --locked --release --manifest-path selene/Cargo.toml --features codec --lib: 541/541 passed.
  • Combined 4-PR validation & SM120/SM121 hardware qualification:
    • FLARE_RUN_CUDA_TESTS=1 SM120 4× RTX PRO 6000 (cn5, with kv_codec_gpu-sm_120a): 28/28 helios::offload:: CUDA tests passed (including multi-GPU split_pools and GPU codec tests).
    • Baseline vs Patched live flare run + selene-manager qualification across DeepSeek-V4.1-Flash-1017 TP4, GLM-5.3-Flash TP2 & TP4 (off/cpu/gpu), Qwen3.8-Flash-Next TP1 & TP2 on SM120 (cn5), and multi-host TP2/TP4 (--roce-ring) on GB10 (cn6–cn9): 0 panics, 0 quarantined bytes, bit-exact pos0 parity across all phases, and clean SIGTERM shutdowns.
  • Material limitations: Windows #[cfg(windows)] IOCP ReadAhead::start attach was reviewed against the existing Windows IOCP attach contract in disk.rs but 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 onto 5df8edd3c.

Discord: D-Rock

@yatesdr
yatesdr force-pushed the fix/selene-dma-lifetime-safety branch 2 times, most recently from a99d917 to 565e0df Compare November 29, 2026 17:26
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
yatesdr force-pushed the fix/selene-dma-lifetime-safety branch from 565e0df to 304dd3a Compare November 29, 2026 17:27
@yatesdr
yatesdr merged commit e2522eb into NVIDIA:main Nov 29, 2026
2 of 3 checks passed
@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 609.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot flare-autobot added area:selene Selene shared prefix-cache pool, protocol, manager, and transfers. bug Something isn't working triage:review Proposed change needs code review; this does not imply merge readiness. labels Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:selene Selene shared prefix-cache pool, protocol, manager, and transfers. bug Something isn't working triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants