Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Dezhen Lu <dinadegttyarenko6@gmail.com>
To: linux-rdma@vger.kernel.org
Subject: tests: CUDA DMA-BUF resources leave exported descriptors open
Date: Wed, 4 Nov 2026 20:48:09 +0100	[thread overview]
Message-ID: <CC55B377-CDCB-4293-8644-602B54B28B18@gmail.com> (raw)

Hello,

At rdma-core master a70151dfec390eb5f7fc5b266f51d601da2a7778,
the CUDA DMA-BUF test resources obtain an FD from
cuMemGetHandleForAddressRange but do not close it after registration.
This affects DmabufCudaRes, MRExDmabufCudaRes,
MRExDmabufDmaHCudaRes, and Mlx5DmabufCudaRes. It occurs on successful
registration and on failures or skips after the FD is obtained. The
integer FD passed to the pyverbs MR constructor is caller-owned.

The following uses a real process FD and a mocked constructor to
exercise the first resource method without requiring a CUDA GPU or RDMA
device. Run it from a checkout with an in-place pyverbs build:

```sh
PYTHONPATH=build/python:tests python3 - <<'PY'
import errno
import os
import sys
from types import SimpleNamespace
from unittest.mock import patch

sys.path.append(sys.path.pop(0))  # Prefer the built pyverbs over the source directory.
import tests.test_cuda_dmabuf as test

fd = os.open('/dev/null', os.O_RDONLY)
res = SimpleNamespace(pd=object(), msg_size=64, mr_access=1,
                      dmabuf_cuda_init=lambda: fd)
try:
    with patch.object(test, 'DmaBufMR', return_value=object()):
        test.DmabufCudaRes.create_mr(res)
    try:
        os.fstat(fd)
    except OSError as exc:
        if exc.errno != errno.EBADF:
            raise
        print('descriptor closed')
    else:
        print('descriptor still open')
finally:
    try:
        os.close(fd)
    except OSError as exc:
        if exc.errno != errno.EBADF:
            raise
PY
```

Observed: descriptor still open. Expected: descriptor closed after
registration returns, including on error. A proposed fix closes it in a
finally block around registration and, for the DMAHandle path, around
handle creation as well. On Linux the RDMA DMA-BUF registration path
acquires its own buffer reference.

I reproduced the behavior on Linux aarch64 with Python 3.12 and a local
rdma-core/pyverbs build. Mock-based FD tests cover the four registration
methods, unsupported and error paths, and DMAHandle creation failure;
they fail on the base and pass with the fix. No CUDA or RDMA traffic was
run for this comparison.


             reply	other threads:[~2026-11-04 19:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 19:48 Dezhen Lu [this message]
2026-11-09 12:13 ` tests: CUDA DMA-BUF resources leave exported descriptors open Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CC55B377-CDCB-4293-8644-602B54B28B18@gmail.com \
    --to=dinadegttyarenko6@gmail.com \
    --cc=linux-rdma@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox