On 10/26/26 06:36, Alistair Popple wrote:
> From: Jason Gunthorpe <[email protected]>
> 
> This attach function always creates a SGT mapping type importer.

Yeah that is a clear NO-GO. The attachment should be the same for the new 
interface as well.

Regards,
Christian.

> 
> Signed-off-by: Jason Gunthorpe <[email protected]>
> ---
>  Documentation/gpu/todo.rst                         |  2 +-
>  drivers/accel/amdxdna/amdxdna_gem.c                |  2 +-
>  drivers/accel/ivpu/ivpu_gem.c                      |  2 +-
>  drivers/accel/qaic/qaic_data.c                     |  2 +-
>  drivers/dma-buf/dma-buf.c                          | 14 +++++++-------
>  drivers/gpu/drm/armada/armada_gem.c                |  2 +-
>  drivers/gpu/drm/drm_gem_shmem_helper.c             |  2 +-
>  drivers/gpu/drm/drm_prime.c                        |  2 +-
>  drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c         |  2 +-
>  .../gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c   |  2 +-
>  drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c          |  2 +-
>  drivers/gpu/drm/tegra/gem.c                        |  4 ++--
>  drivers/iio/industrialio-buffer.c                  |  2 +-
>  .../media/common/videobuf2/videobuf2-dma-contig.c  |  2 +-
>  drivers/media/common/videobuf2/videobuf2-dma-sg.c  |  2 +-
>  .../media/platform/nvidia/tegra-vde/dmabuf-cache.c |  2 +-
>  drivers/misc/fastrpc.c                             |  2 +-
>  drivers/usb/gadget/function/f_fs.c                 |  2 +-
>  drivers/xen/gntdev-dmabuf.c                        |  2 +-
>  include/linux/dma-buf.h                            | 10 +++++-----
>  io_uring/zcrx.c                                    |  2 +-
>  net/core/devmem.c                                  |  2 +-
>  22 files changed, 33 insertions(+), 33 deletions(-)
> 
> diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
> index 14cf37590fc7..be0397c197f1 100644
> --- a/Documentation/gpu/todo.rst
> +++ b/Documentation/gpu/todo.rst
> @@ -633,7 +633,7 @@ Remove automatic page mapping from dma-buf importing
>  
>  When importing dma-bufs, the dma-buf and PRIME frameworks automatically map
>  imported pages into the importer's DMA area. drm_gem_prime_fd_to_handle() and
> -drm_gem_prime_handle_to_fd() require that importers call dma_buf_attach()
> +drm_gem_prime_handle_to_fd() require that importers call dma_buf_sgt_attach()
>  even if they never do actual device DMA, but only CPU access through
>  dma_buf_vmap(). This is a problem for USB devices, which do not support DMA
>  operations.
> diff --git a/drivers/accel/amdxdna/amdxdna_gem.c 
> b/drivers/accel/amdxdna/amdxdna_gem.c
> index a7e759bb0460..2b2f1e9fb9ec 100644
> --- a/drivers/accel/amdxdna/amdxdna_gem.c
> +++ b/drivers/accel/amdxdna/amdxdna_gem.c
> @@ -893,7 +893,7 @@ amdxdna_gem_prime_import(struct drm_device *dev, struct 
> dma_buf *dma_buf)
>  
>       get_dma_buf(dma_buf);
>  
> -     attach = dma_buf_attach(dma_buf, dev->dev);
> +     attach = dma_buf_sgt_attach(dma_buf, dev->dev);
>       if (IS_ERR(attach)) {
>               ret = PTR_ERR(attach);
>               goto put_buf;
> diff --git a/drivers/accel/ivpu/ivpu_gem.c b/drivers/accel/ivpu/ivpu_gem.c
> index 8d6ed95ccc7c..d1c99b974a34 100644
> --- a/drivers/accel/ivpu/ivpu_gem.c
> +++ b/drivers/accel/ivpu/ivpu_gem.c
> @@ -219,7 +219,7 @@ struct drm_gem_object *ivpu_gem_prime_import(struct 
> drm_device *dev,
>       struct ivpu_bo *bo;
>       int ret;
>  
> -     attach = dma_buf_attach(dma_buf, attach_dev);
> +     attach = dma_buf_sgt_attach(dma_buf, attach_dev);
>       if (IS_ERR(attach))
>               return ERR_CAST(attach);
>  
> diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
> index 92d49448df72..88331028b7bf 100644
> --- a/drivers/accel/qaic/qaic_data.c
> +++ b/drivers/accel/qaic/qaic_data.c
> @@ -850,7 +850,7 @@ struct drm_gem_object *qaic_gem_prime_import(struct 
> drm_device *dev, struct dma_
>       obj = &bo->base;
>       get_dma_buf(dma_buf);
>  
> -     attach = dma_buf_attach(dma_buf, dev->dev);
> +     attach = dma_buf_sgt_attach(dma_buf, dev->dev);
>       if (IS_ERR(attach)) {
>               ret = PTR_ERR(attach);
>               goto attach_fail;
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index 12604c60122e..06bc25eff079 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -671,7 +671,7 @@ static struct file *dma_buf_getfile(size_t size, int 
> flags)
>   * 2. Userspace passes this file-descriptors to all drivers it wants this 
> buffer
>   *    to share with: First the file descriptor is converted to a &dma_buf 
> using
>   *    dma_buf_get(). Then the buffer is attached to the device using
> - *    dma_buf_attach().
> + *    dma_buf_sgt_attach().
>   *
>   *    Up to this stage the exporter is still free to migrate or reallocate 
> the
>   *    backing storage.
> @@ -966,7 +966,7 @@ dma_buf_pin_on_map(struct dma_buf_attachment *attach)
>   * 2. Importers must not hold the dma-buf reservation lock when calling these
>   *    functions:
>   *
> - *     - dma_buf_attach()
> + *     - dma_buf_sgt_attach()
>   *     - dma_buf_dynamic_attach()
>   *     - dma_buf_detach()
>   *     - dma_buf_export()
> @@ -1100,15 +1100,15 @@ struct dma_buf_attachment *dma_buf_mapping_attach(
>  EXPORT_SYMBOL_NS_GPL(dma_buf_mapping_attach, "DMA_BUF");
>  
>  /**
> - * dma_buf_attach - Wrapper for dma_buf_mapping_attach
> + * dma_buf_sgt_attach - Wrapper for dma_buf_mapping_attach
>   * @dmabuf:  [in]    buffer to attach device to.
>   * @dev:     [in]    device to be attached.
>   *
>   * Wrapper to call dma_buf_mapping_attach() for drivers which still use a 
> static
>   * mapping.
>   */
> -struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
> -                                       struct device *dev)
> +struct dma_buf_attachment *dma_buf_sgt_attach(struct dma_buf *dmabuf,
> +                                           struct device *dev)
>  {
>       struct dma_buf_mapping_match sgt_match[] = {
>               DMA_BUF_IMAPPING_SGT(dev, DMA_SGT_NO_P2P),
> @@ -1117,7 +1117,7 @@ struct dma_buf_attachment *dma_buf_attach(struct 
> dma_buf *dmabuf,
>       return dma_buf_mapping_attach(dmabuf, sgt_match, ARRAY_SIZE(sgt_match),
>                                     NULL, NULL);
>  }
> -EXPORT_SYMBOL_NS_GPL(dma_buf_attach, "DMA_BUF");
> +EXPORT_SYMBOL_NS_GPL(dma_buf_sgt_attach, "DMA_BUF");
>  
>  /**
>   * dma_buf_dynamic_attach - Add the device to dma_buf's attachments list
> @@ -1149,7 +1149,7 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_dynamic_attach, "DMA_BUF");
>   * @dmabuf:  [in]    buffer to detach from.
>   * @attach:  [in]    attachment to be detached; is free'd after this call.
>   *
> - * Clean up a device attachment obtained by calling dma_buf_attach().
> + * Clean up a device attachment obtained by calling dma_buf_sgt_attach().
>   *
>   * Optionally this calls &dma_buf_ops.detach for device-specific detach.
>   */
> diff --git a/drivers/gpu/drm/armada/armada_gem.c 
> b/drivers/gpu/drm/armada/armada_gem.c
> index 72c7cd2b3fb9..438f33304eab 100644
> --- a/drivers/gpu/drm/armada/armada_gem.c
> +++ b/drivers/gpu/drm/armada/armada_gem.c
> @@ -518,7 +518,7 @@ armada_gem_prime_import(struct drm_device *dev, struct 
> dma_buf *buf)
>               }
>       }
>  
> -     attach = dma_buf_attach(buf, dev->dev);
> +     attach = dma_buf_sgt_attach(buf, dev->dev);
>       if (IS_ERR(attach))
>               return ERR_CAST(attach);
>  
> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c 
> b/drivers/gpu/drm/drm_gem_shmem_helper.c
> index d654a22a30de..9e937af2ee73 100644
> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> @@ -964,7 +964,7 @@ struct drm_gem_object 
> *drm_gem_shmem_prime_import_no_map(struct drm_device *dev,
>               return obj;
>       }
>  
> -     attach = dma_buf_attach(dma_buf, dev->dev);
> +     attach = dma_buf_sgt_attach(dma_buf, dev->dev);
>       if (IS_ERR(attach))
>               return ERR_CAST(attach);
>  
> diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
> index 3ffbe3d28929..3084e8c28e53 100644
> --- a/drivers/gpu/drm/drm_prime.c
> +++ b/drivers/gpu/drm/drm_prime.c
> @@ -999,7 +999,7 @@ struct drm_gem_object *drm_gem_prime_import_dev(struct 
> drm_device *dev,
>       if (!dev->driver->gem_prime_import_sg_table)
>               return ERR_PTR(-EINVAL);
>  
> -     attach = dma_buf_attach(dma_buf, attach_dev);
> +     attach = dma_buf_sgt_attach(dma_buf, attach_dev);
>       if (IS_ERR(attach))
>               return ERR_CAST(attach);
>  
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c 
> b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
> index 7f939c281308..9865a7a9ad8f 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
> @@ -306,7 +306,7 @@ struct drm_gem_object *i915_gem_prime_import(struct 
> drm_device *dev,
>               return ERR_PTR(-E2BIG);
>  
>       /* need to attach */
> -     attach = dma_buf_attach(dma_buf, dev->dev);
> +     attach = dma_buf_sgt_attach(dma_buf, dev->dev);
>       if (IS_ERR(attach))
>               return ERR_CAST(attach);
>  
> diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c 
> b/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c
> index 6b6d235fd3e9..3c193e6d9d11 100644
> --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c
> +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c
> @@ -287,7 +287,7 @@ static int igt_dmabuf_import_same_driver(struct 
> drm_i915_private *i915,
>               goto out_import;
>  
>       /* Now try a fake an importer */
> -     import_attach = dma_buf_attach(dmabuf, obj->base.dev->dev);
> +     import_attach = dma_buf_sgt_attach(dmabuf, obj->base.dev->dev);
>       if (IS_ERR(import_attach)) {
>               err = PTR_ERR(import_attach);
>               goto out_import;
> diff --git a/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c 
> b/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c
> index c549b94b2e8a..ca0962a99509 100644
> --- a/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c
> +++ b/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c
> @@ -115,7 +115,7 @@ struct drm_gem_object *omap_gem_prime_import(struct 
> drm_device *dev,
>               }
>       }
>  
> -     attach = dma_buf_attach(dma_buf, dev->dev);
> +     attach = dma_buf_sgt_attach(dma_buf, dev->dev);
>       if (IS_ERR(attach))
>               return ERR_CAST(attach);
>  
> diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c
> index f06826fe8366..803409824711 100644
> --- a/drivers/gpu/drm/tegra/gem.c
> +++ b/drivers/gpu/drm/tegra/gem.c
> @@ -81,7 +81,7 @@ static struct host1x_bo_mapping *tegra_bo_pin(struct device 
> *dev, struct host1x_
>       if (obj->dma_buf) {
>               struct dma_buf *buf = obj->dma_buf;
>  
> -             map->attach = dma_buf_attach(buf, dev);
> +             map->attach = dma_buf_sgt_attach(buf, dev);
>               if (IS_ERR(map->attach)) {
>                       err = PTR_ERR(map->attach);
>                       goto free;
> @@ -475,7 +475,7 @@ static struct tegra_bo *tegra_bo_import(struct drm_device 
> *drm,
>        * domain, map it first to the DRM device to get an sgt.
>        */
>       if (tegra->domain) {
> -             attach = dma_buf_attach(buf, drm->dev);
> +             attach = dma_buf_sgt_attach(buf, drm->dev);
>               if (IS_ERR(attach)) {
>                       err = PTR_ERR(attach);
>                       goto free;
> diff --git a/drivers/iio/industrialio-buffer.c 
> b/drivers/iio/industrialio-buffer.c
> index f81154642bcd..abffbcc76c4c 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -1717,7 +1717,7 @@ static int iio_buffer_attach_dmabuf(struct 
> iio_dev_buffer_pair *ib,
>               goto err_free_priv;
>       }
>  
> -     attach = dma_buf_attach(dmabuf, dma_dev);
> +     attach = dma_buf_sgt_attach(dmabuf, dma_dev);
>       if (IS_ERR(attach)) {
>               err = PTR_ERR(attach);
>               goto err_dmabuf_put;
> diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c 
> b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> index e13521b5c0e8..c7fa86cba8ad 100644
> --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> @@ -789,7 +789,7 @@ static void *vb2_dc_attach_dmabuf(struct vb2_buffer *vb, 
> struct device *dev,
>       buf->vb = vb;
>  
>       /* create attachment for the dmabuf with the user device */
> -     dba = dma_buf_attach(dbuf, buf->dev);
> +     dba = dma_buf_sgt_attach(dbuf, buf->dev);
>       if (IS_ERR(dba)) {
>               pr_err("failed to attach dmabuf\n");
>               kfree(buf);
> diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c 
> b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
> index 59e346a5d48b..4c93b7f58e1f 100644
> --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
> +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
> @@ -638,7 +638,7 @@ static void *vb2_dma_sg_attach_dmabuf(struct vb2_buffer 
> *vb, struct device *dev,
>  
>       buf->dev = dev;
>       /* create attachment for the dmabuf with the user device */
> -     dba = dma_buf_attach(dbuf, buf->dev);
> +     dba = dma_buf_sgt_attach(dbuf, buf->dev);
>       if (IS_ERR(dba)) {
>               pr_err("failed to attach dmabuf\n");
>               kfree(buf);
> diff --git a/drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c 
> b/drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c
> index 55d58a4dbbe2..d80282ebe4b4 100644
> --- a/drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c
> +++ b/drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c
> @@ -96,7 +96,7 @@ int tegra_vde_dmabuf_cache_map(struct tegra_vde *vde,
>               goto ref;
>       }
>  
> -     attachment = dma_buf_attach(dmabuf, dev);
> +     attachment = dma_buf_sgt_attach(dmabuf, dev);
>       if (IS_ERR(attachment)) {
>               dev_err(dev, "Failed to attach dmabuf\n");
>               err = PTR_ERR(attachment);
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index 375ce39c78c9..24ae1038b634 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -904,7 +904,7 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, 
> int fd,
>               goto get_err;
>       }
>  
> -     map->attach = dma_buf_attach(map->buf, sess->dev);
> +     map->attach = dma_buf_sgt_attach(map->buf, sess->dev);
>       if (IS_ERR(map->attach)) {
>               dev_err(sess->dev, "Failed to attach dmabuf\n");
>               err = PTR_ERR(map->attach);
> diff --git a/drivers/usb/gadget/function/f_fs.c 
> b/drivers/usb/gadget/function/f_fs.c
> index 4016edfa4c02..bfa24bcfe84c 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -1549,7 +1549,7 @@ static int ffs_dmabuf_attach(struct file *file, int fd)
>       if (IS_ERR(dmabuf))
>               return PTR_ERR(dmabuf);
>  
> -     attach = dma_buf_attach(dmabuf, gadget->dev.parent);
> +     attach = dma_buf_sgt_attach(dmabuf, gadget->dev.parent);
>       if (IS_ERR(attach)) {
>               err = PTR_ERR(attach);
>               goto err_dmabuf_put;
> diff --git a/drivers/xen/gntdev-dmabuf.c b/drivers/xen/gntdev-dmabuf.c
> index cd851eb04a69..e7ffb546e717 100644
> --- a/drivers/xen/gntdev-dmabuf.c
> +++ b/drivers/xen/gntdev-dmabuf.c
> @@ -580,7 +580,7 @@ dmabuf_imp_to_refs(struct gntdev_dmabuf_priv *priv, 
> struct device *dev,
>       gntdev_dmabuf->priv = priv;
>       gntdev_dmabuf->fd = fd;
>  
> -     attach = dma_buf_attach(dma_buf, dev);
> +     attach = dma_buf_sgt_attach(dma_buf, dev);
>       if (IS_ERR(attach)) {
>               ret = ERR_CAST(attach);
>               goto fail_free_obj;
> diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
> index b264e1c4a9df..208752eb93d9 100644
> --- a/include/linux/dma-buf.h
> +++ b/include/linux/dma-buf.h
> @@ -77,7 +77,7 @@ struct dma_buf_ops {
>       /**
>        * @attach:
>        *
> -      * This is called from dma_buf_attach() to make sure that a given
> +      * This is called from dma_buf_sgt_attach() to make sure that a given
>        * &dma_buf_attachment.dev can access the provided &dma_buf. Exporters
>        * which support buffer objects in special locations like VRAM or
>        * device-specific carveout areas should check whether the buffer could
> @@ -125,7 +125,7 @@ struct dma_buf_ops {
>        * exclusive with @cache_sgt_mapping.
>        *
>        * This is called automatically for non-dynamic importers from
> -      * dma_buf_attach().
> +      * dma_buf_sgt_attach().
>        *
>        * Note that similar to non-dynamic exporters in their @map_dma_buf
>        * callback the driver must guarantee that the memory is available for
> @@ -513,7 +513,7 @@ struct dma_buf_attach_ops {
>   * and its user device(s). The list contains one attachment struct per device
>   * attached to the buffer.
>   *
> - * An attachment is created by calling dma_buf_attach(), and released again 
> by
> + * An attachment is created by calling dma_buf_sgt_attach(), and released 
> again by
>   * calling dma_buf_detach(). The DMA mapping itself needed to initiate a
>   * transfer is created by dma_buf_sgt_map_attachment() and freed again by 
> calling
>   * dma_buf_sgt_unmap_attachment().
> @@ -591,8 +591,8 @@ static inline bool dma_buf_is_dynamic(struct dma_buf 
> *dmabuf)
>       return !!dmabuf->ops->pin;
>  }
>  
> -struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
> -                                       struct device *dev);
> +struct dma_buf_attachment *dma_buf_sgt_attach(struct dma_buf *dmabuf,
> +                                           struct device *dev);
>  struct dma_buf_attachment *
>  dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
>                      const struct dma_buf_attach_ops *importer_ops,
> diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
> index 67f74ce4f096..2cbf65b29f89 100644
> --- a/io_uring/zcrx.c
> +++ b/io_uring/zcrx.c
> @@ -175,7 +175,7 @@ static int io_import_dmabuf(struct io_zcrx_ifq *ifq,
>               goto err;
>       }
>  
> -     mem->attach = dma_buf_attach(mem->dmabuf, ifq->dev);
> +     mem->attach = dma_buf_sgt_attach(mem->dmabuf, ifq->dev);
>       if (IS_ERR(mem->attach)) {
>               ret = PTR_ERR(mem->attach);
>               mem->attach = NULL;
> diff --git a/net/core/devmem.c b/net/core/devmem.c
> index f30fa375c9ab..d7c08da306cf 100644
> --- a/net/core/devmem.c
> +++ b/net/core/devmem.c
> @@ -234,7 +234,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
>       binding->dmabuf = dmabuf;
>       binding->direction = direction;
>  
> -     binding->attachment = dma_buf_attach(binding->dmabuf, dma_dev);
> +     binding->attachment = dma_buf_sgt_attach(binding->dmabuf, dma_dev);
>       if (IS_ERR(binding->attachment)) {
>               err = PTR_ERR(binding->attachment);
>               NL_SET_ERR_MSG(extack, "Failed to bind dmabuf to device");

Reply via email to