public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Edward Srouji <edwards@nvidia.com>
Cc: "Jason Gunthorpe" <jgg@ziepe.ca>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	"Christian König" <christian.koenig@amd.com>,
	linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linaro-mm-sig@lists.linaro.org,
	"Yishai Hadas" <yishaih@nvidia.com>
Subject: Re: [PATCH rdma-next 1/2] RDMA/uverbs: Add DMABUF object type and operations
Date: Sun, 25 Jan 2026 16:31:43 +0200	[thread overview]
Message-ID: <20260125143143.GF13967@unreal> (raw)
In-Reply-To: <20260108-dmabuf-export-v1-1-6d47d46580d3@nvidia.com>

On Thu, Jan 08, 2026 at 01:11:14PM +0200, Edward Srouji wrote:
> From: Yishai Hadas <yishaih@nvidia.com>
> 
> Expose DMABUF functionality to userspace through the uverbs interface,
> enabling InfiniBand/RDMA devices to export PCI based memory regions
> (e.g. device memory) as DMABUF file descriptors. This allows
> zero-copy sharing of RDMA memory with other subsystems that support the
> dma-buf framework.
> 
> A new UVERBS_OBJECT_DMABUF object type and allocation method were
> introduced.
> 
> During allocation, uverbs invokes the driver to supply the
> rdma_user_mmap_entry associated with the given page offset (pgoff).
> 
> Based on the returned rdma_user_mmap_entry, uverbs requests the driver
> to provide the corresponding physical-memory details as well as the
> driver’s PCI provider information.
> 
> Using this information, dma_buf_export() is called; if it succeeds,
> uobj->object is set to the underlying file pointer returned by the
> dma-buf framework.
> 
> The file descriptor number follows the standard uverbs allocation flow,
> but the file pointer comes from the dma-buf subsystem, including its own
> fops and private data.
> 
> Because of this, alloc_begin_fd_uobject() must handle cases where
> fd_type->fops is NULL, and both alloc_commit_fd_uobject() and
> alloc_abort_fd_uobject() must account for whether filp->private_data
> exists, since it is only populated after a successful dma_buf_export().
> 
> When an mmap entry is removed, uverbs iterates over its associated
> DMABUFs, marks them as revoked, and calls dma_buf_move_notify() so that
> their importers are notified.
> 
> The same procedure applies during the disassociate flow; final cleanup
> occurs when the application closes the file.
> 
> Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
> Signed-off-by: Edward Srouji <edwards@nvidia.com>
> ---
>  drivers/infiniband/core/Makefile                  |   1 +
>  drivers/infiniband/core/device.c                  |   2 +
>  drivers/infiniband/core/ib_core_uverbs.c          |  19 +++
>  drivers/infiniband/core/rdma_core.c               |  63 ++++----
>  drivers/infiniband/core/rdma_core.h               |   1 +
>  drivers/infiniband/core/uverbs.h                  |  10 ++
>  drivers/infiniband/core/uverbs_std_types_dmabuf.c | 172 ++++++++++++++++++++++
>  drivers/infiniband/core/uverbs_uapi.c             |   1 +
>  include/rdma/ib_verbs.h                           |   9 ++
>  include/rdma/uverbs_types.h                       |   1 +
>  include/uapi/rdma/ib_user_ioctl_cmds.h            |  10 ++
>  11 files changed, 263 insertions(+), 26 deletions(-)

<...>

> +static struct sg_table *
> +uverbs_dmabuf_map(struct dma_buf_attachment *attachment,
> +		  enum dma_data_direction dir)
> +{
> +	struct ib_uverbs_dmabuf_file *priv = attachment->dmabuf->priv;
> +
> +	dma_resv_assert_held(priv->dmabuf->resv);
> +
> +	if (priv->revoked)
> +		return ERR_PTR(-ENODEV);
> +
> +	return dma_buf_phys_vec_to_sgt(attachment, priv->provider,
> +				       &priv->phys_vec, 1, priv->phys_vec.len,
> +				       dir);
> +}
> +
> +static void uverbs_dmabuf_unmap(struct dma_buf_attachment *attachment,
> +				struct sg_table *sgt,
> +				enum dma_data_direction dir)
> +{
> +	dma_buf_free_sgt(attachment, sgt, dir);
> +}

Unfortunately, it is not enough. Exporters should count their
map<->unmap calls and make sure that they are equal.

See this VFIO change https://lore.kernel.org/kvm/20260124-dmabuf-revoke-v5-4-f98fca917e96@nvidia.com/

Thanks

  parent reply	other threads:[~2026-01-25 14:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08 11:11 [PATCH rdma-next 0/2] RDMA: Add support for exporting dma-buf file descriptors Edward Srouji
2026-01-08 11:11 ` [PATCH rdma-next 1/2] RDMA/uverbs: Add DMABUF object type and operations Edward Srouji
2026-01-20 18:15   ` Jason Gunthorpe
2026-01-21  8:32     ` Leon Romanovsky
2026-01-21 13:56       ` Jason Gunthorpe
2026-01-21 16:27         ` Yishai Hadas
2026-01-21 10:07     ` Yishai Hadas
2026-01-25 14:31   ` Leon Romanovsky [this message]
2026-01-08 11:11 ` [PATCH rdma-next 2/2] RDMA/mlx5: Implement DMABUF export ops Edward Srouji
2026-01-20 18:18   ` Jason Gunthorpe
2026-01-21 10:35     ` Yishai Hadas

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=20260125143143.GF13967@unreal \
    --to=leon@kernel.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=edwards@nvidia.com \
    --cc=jgg@ziepe.ca \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=yishaih@nvidia.com \
    /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