Skip to content

nvproxy: support exporting GPU memory to a dma-buf fd#13736

Open
ayushr2 wants to merge 2 commits into
google:masterfrom
ayushr2:rdma-nvproxy
Open

nvproxy: support exporting GPU memory to a dma-buf fd#13736
ayushr2 wants to merge 2 commits into
google:masterfrom
ayushr2:rdma-nvproxy

Conversation

@ayushr2

@ayushr2 ayushr2 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Add support for NV_ESC_EXPORT_TO_DMABUF_FD, which CUDA issues to export
GPU memory as a dma-buf file descriptor. This is the mechanism used for
GPUDirect RDMA: the returned fd is handed to ibv_reg_dmabuf_mr so a NIC
can DMA directly to and from GPU memory.

The driver allocates a host dma-buf and returns its fd in the ioctl's FD
field; nvproxy wraps that host fd in a sentry file description installed
in the application's fd table. The wrapper implements vfs.HostFDProvider
so the RDMA device proxy can recover the host fd for registration.

This ioctl exposes GPU memory to external devices, so it is gated behind
a new privileged driver capability, CapRDMA, and is only permitted (and
its seccomp filter only installed) when that capability is enabled.
CapRDMA is enabled automatically when RDMA support is requested.

Co-authored-by: Alessio Ricci Toniolo alessio@modal.com

ayushr2 and others added 2 commits July 16, 2026 19:49
Containers with /dev/infiniband/uverbs* devices need a sysfs surface for
device discovery: libibverbs enumerates /sys/class/infiniband_verbs, and
NCCL builds its hardware topology by resolving /sys/class symlinks with
realpath() and walking the PCI hierarchy.

This adds a --rdmaproxy flag which will gate all RDMA support. For now it
only wires up the sysfs topology: runsc snapshots the host sysfs closure
derived from the spec's uverbs devices (ibdevs, netdevs, PCI ancestor
chains, GPU functions, NUMA nodes) before pivot_root, and the sentry
constructs a path-identical virtual tree: one canonical /sys/devices/pci...
subtree per device, with /sys/class/* and /sys/bus/pci/devices as symlink
farms matching the kernel layout. Per-port dynamic state (RoCE GID tables,
link state, counters) is served live through targeted read-only bind mounts
of the per-ibdev ports subtrees; identity and PCI attributes are a static
snapshot, since the collecting process and the constructed sandbox tree do
not observe the same sysfs mount (the RDMA netdevs move into the sandbox
network namespace only after the sandbox is created).

Each PCI function directory also gets a subsystem symlink into a
synthesized /sys/bus/pci, and every node's bus gets a pci_bus entry: NCCL
classifies a directory as a PCI device by following its subsystem symlink,
and aborts topology discovery without it.

The verbs device proxy that makes RDMA usable end-to-end is not part of
this change; --rdmaproxy is a work in progress and RDMA is not yet
functional.

Co-authored-by: Alessio Ricci Toniolo <alessio@modal.com>
Add support for NV_ESC_EXPORT_TO_DMABUF_FD, which CUDA issues to export
GPU memory as a dma-buf file descriptor. This is the mechanism used for
GPUDirect RDMA: the returned fd is handed to ibv_reg_dmabuf_mr so a NIC
can DMA directly to and from GPU memory.

The driver allocates a host dma-buf and returns its fd in the ioctl's FD
field; nvproxy wraps that host fd in a sentry file description installed
in the application's fd table. The wrapper implements vfs.HostFDProvider
so the RDMA device proxy can recover the host fd for registration.

This ioctl exposes GPU memory to external devices, so it is gated behind
a new privileged driver capability, CapRDMA, and is only permitted (and
its seccomp filter only installed) when that capability is enabled.
CapRDMA is enabled automatically when RDMA support is requested.

Co-authored-by: Alessio Ricci Toniolo <alessio@modal.com>
@ayushr2

ayushr2 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

This is stacked on top of #13712, so you just need to review the nvproxy: commit, which is ~250 lines of code. If you want, you can also review at ayushr2#3.

@ayushr2

ayushr2 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

cc @trantoji @TheCoolDinosuar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant