Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alistair Popple" <apopple@nvidia.com>
Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	linux-rdma@vger.kernel.org, kvm@vger.kernel.org,
	media-ci@linuxtv.org
Subject: Re: [PATCH RFC 15/16] drm/xe/dma-buf: Export a dma_shared_buf instead of mapping the buffer
Date: Tue, 01 Dec 2026 07:26:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-242768@kernel.org> (raw)
In-Reply-To: <20261201-dmabuf_shared_buf_v1_xe_rc5-v1-15-b672717c7fc9@nvidia.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/xe/dma-buf: xe_dma_buf_attach() clears peer2peer for
  iommufd attachments
--

commit afc228f35dfc8ad8b39e640599fbccbde0209c02
Author: Alistair Popple <apopple@nvidia.com>

drm/xe/dma-buf: Export a dma_shared_buf instead of mapping the buffer

This commit replaces xe_dma_buf_map() and xe_dma_buf_unmap() with
map_dma_shared_buf() and unmap_dma_shared_buf() callbacks, initializing
a p2pdma provider for the VRAM BAR so VRAM and system memory buffers are
exported as dma_shared_buf ranges.

> diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c
> index 97299ca8f8316..8727ca456f2fb 100644
> --- a/drivers/gpu/drm/xe/xe_dma_buf.c
> +++ b/drivers/gpu/drm/xe/xe_dma_buf.c
> @@ -111,14 +111,14 @@ static void xe_dma_buf_unpin(struct dma_buf_attachment *attach)
>  	xe_bo_unpin_external(bo);
>  }
>  
> -static struct sg_table *xe_dma_buf_map(struct dma_buf_attachment *attach,
> -				       enum dma_data_direction dir)
> +static struct dma_shared_buf *
> +xe_dma_buf_map_dma_shared_buf(struct dma_buf_attachment *attach)
>  {
>  	struct dma_buf *dma_buf = attach->dmabuf;
>  	struct drm_gem_object *obj = dma_buf->priv;
>  	struct xe_bo *bo = gem_to_xe_bo(obj);
>  	struct drm_exec *exec = XE_VALIDATION_UNSUPPORTED;
> -	struct sg_table *sgt;
> +	struct dma_shared_buf *shared_buf;
>  	int r = 0;
>  
>  	if (xe_bo_is_purged(bo))
> @@ -138,49 +138,24 @@ static struct sg_table *xe_dma_buf_map(struct dma_buf_attachment *attach,
>  
>  	switch (bo->ttm.resource->mem_type) {
>  	case XE_PL_TT:
> -		sgt = drm_prime_pages_to_sg(obj->dev,
> -					    bo->ttm.ttm->pages,
> -					    obj->size >> PAGE_SHIFT);
> -		if (IS_ERR(sgt))
> -			return sgt;
> -
> -		if (dma_map_sgtable(attach->dev, sgt, dir,
> -				    DMA_ATTR_SKIP_CPU_SYNC))
> -			goto error_free;
> -		break;
> -
> +		shared_buf = dma_shared_buf_from_pages(bo->ttm.ttm->pages,
> +						       obj->size >> PAGE_SHIFT);
> +		if (!IS_ERR(shared_buf))
> +			shared_buf->attrs = DMA_ATTR_SKIP_CPU_SYNC;
> +		return shared_buf;
>  	case XE_PL_VRAM0:
>  	case XE_PL_VRAM1:
> -		r = xe_ttm_vram_mgr_alloc_sgt(xe_bo_device(bo),
> -					      bo->ttm.resource, 0,
> -					      bo->ttm.base.size, attach->dev,
> -					      dir, &sgt);
> -		if (r)
> -			return ERR_PTR(r);
> -		break;
> +		return xe_ttm_vram_mgr_alloc_shared_buf(xe_bo_device(bo),
> +							bo->ttm.resource);

[Severity: High]
Can iommufd ever reach the XE_PL_VRAM0 / XE_PL_VRAM1 path here to map
VRAM buffers?

When iopt_map_dmabuf() attaches to the dma-buf, it passes
iommufd_global_device() (a virtual miscdevice, not a PCI device) as
attach->dev.  In xe_dma_buf_attach(), pci_p2pdma_distance() returns -1
because find_parent_pci_dev(attach->dev) is NULL:

drivers/gpu/drm/xe/xe_dma_buf.c:xe_dma_buf_attach() {
	...
	if (attach->peer2peer &&
	    pci_p2pdma_distance(to_pci_dev(obj->dev->dev), attach->dev, verbose_p2p_dist) < 0)
		attach->peer2peer = false;

	if (!attach->peer2peer && !xe_bo_can_migrate(gem_to_xe_bo(obj), XE_PL_TT))
		return -EOPNOTSUPP;
	...
}

Clearing attach->peer2peer causes VRAM-only buffer objects to fail
iommufd import with -EOPNOTSUPP, while buffers that allow XE_PL_TT are
migrated out of VRAM into system memory and pinned there by
xe_dma_buf_pin().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-dmabuf_shared_buf_v1_xe_rc5-v1-0-b672717c7fc9@nvidia.com?part=15

  reply	other threads:[~2026-12-01  7:26 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  7:06 [PATCH RFC 00/16] dma-buf: Introduce dma_shared_buf and dma_addr_list to replace sg_table Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 01/16] treewide: Rename dma_buf_(un)map_attachment() to dma_buf_(un)map_sgt() Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 02/16] dma-shared-buf: Add struct dma_shared_buf Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 03/16] dma-shared-buf: Add dma_shared_buf_iommu_map() Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 04/16] dma-shared-buf: Add dma_addr_list_to_sgt() Alistair Popple
2026-12-01  7:19   ` sashiko-bot
2026-12-01  7:06 ` [PATCH RFC 05/16] dma-shared-buf: Add dma_shared_buf_from_pages() Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 06/16] dma-buf: Allow exporters to hand out a dma_shared_buf Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 07/16] dma-buf: Add dma_buf_iommu_map() for IOMMU domain importers Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 08/16] dma-buf: Factor out the pin and fence wait around the exporter's map Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 09/16] dma-buf: Add dma_buf_map_dma_list() for DMA address only importers Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 10/16] vfio/pci: Export a dma_shared_buf instead of mapping the buffer Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 11/16] RDMA/uverbs: " Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 12/16] dma-buf: Remove dma_buf_phys_vec_to_sgt() and dma_buf_free_sgt() Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 13/16] iommufd: Map DMA-bufs through dma_buf_iommu_map() Alistair Popple
2026-12-01  7:28   ` sashiko-bot
2026-12-01  7:06 ` [PATCH RFC 14/16] vfio/pci: Remove vfio_pci_dma_buf_iommufd_map() Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 15/16] drm/xe/dma-buf: Export a dma_shared_buf instead of mapping the buffer Alistair Popple
2026-12-01  7:26   ` sashiko-bot [this message]
2026-12-01  7:06 ` [PATCH RFC 16/16] drm/xe: Import DMA-bufs as a DMA address list Alistair Popple
2026-12-01  7:28 ` [PATCH RFC 00/16] dma-buf: Introduce dma_shared_buf and dma_addr_list to replace sg_table sashiko-bot

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=sashiko-outbox-242768@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=apopple@nvidia.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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