net: close DMA-BUF fd on the regMrDmaBuf-failure fallback path#2267
Open
EylonKrause wants to merge 1 commit into
Open
net: close DMA-BUF fd on the regMrDmaBuf-failure fallback path#2267EylonKrause wants to merge 1 commit into
EylonKrause wants to merge 1 commit into
Conversation
sendProxyRegBuffer and recvProxyRegBuffer open a DMA-BUF fd via cuMemGetHandleForAddressRange and register it with regMrDmaBuf. The fd was declared inside the `if (resources->useDmaBuf)` block and closed only on the inline success path. When regMrDmaBuf fails, NCCLCHECKGOTO jumps to the `peermem` label, where the code falls back to a plain regMr; if that fallback succeeds the function returns success with the DMA-BUF fd still open -- a per-registration fd leak on the fallback path. Hoist the fd to the enclosing scope, initialize it to -1, and close it once at the `peermem` label on every exit path, guarded by `!= -1` so the cuMemGetHandleForAddressRange-failure path (where no fd was opened) does not close a bogus descriptor. This mirrors the existing idiom in collNetRegBuffer (src/transport/coll_net.cc), which already uses the same `int dmabuf_fd = -1;` declaration plus guarded close. Signed-off-by: EylonKrause <eylon1909@gmail.com>
Author
|
Disclosure: this contribution was authored with an AI coding assistant (Claude) and reviewed before submission. |
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.
Summary
sendProxyRegBufferandrecvProxyRegBuffer(src/transport/net.cc) leak the DMA-BUF file descriptor on theregMrDmaBuf-failure fallback path.Both functions open a DMA-BUF fd via
cuMemGetHandleForAddressRangeand register it withregMrDmaBuf:When
regMrDmaBuffails,NCCLCHECKGOTOjumps topeermemwithdmabuf_fdstill open andneedRegstilltrue, so the code falls back to a plainregMr. If that fallback succeeds, the function returns success while the DMA-BUF fd is never closed — a per-registration fd leak on the fallback path. Under repeated buffer registration this exhausts the process fd table.Fix
Hoist
dmabuf_fdto the enclosing scope, initialize it to-1, drop the inline close, and close once at thepeermemlabel on every exit path — guarded by!= -1so thecuMemGetHandleForAddressRange-failure path (where no fd was opened) does not close a bogus descriptor.This mirrors the idiom already used in
collNetRegBuffer(src/transport/coll_net.cc), which declaresint dmabuf_fd = -1;at function scope and performs a guarded close at its cleanup label. The change makes the two proxy-side reg paths consistent with the collnet path.Testing
-fsyntax-onlycompile ofsrc/transport/net.ccis clean (validates the hoisted-scope +peermemfall-through close: no double-close, no jump-crosses-initialization).coll_net.ccguarded-close pattern.Signed-off-by: EylonKrause eylon1909@gmail.com