Skip to contentSkip to conversation

drm/prime: introduce DRM_PRIME_FD_TO_HANDLE_NO_MOVE

RFC PATCH In review Simon Ser 3 participants 6 messages Oct 13, 2024 – Oct 18, 2024

Subsystems (8)
lore
Share & tools
lore

Simon Ser

author
#0 lore raw

RFC PATCH 1/1 drm/prime: introduce DRM_PRIME_FD_TO_HANDLE_NO_MOVE

This is a flag to opt-out of the automagic buffer migration to system memory when importing a DMA-BUF.

In multi-GPU scenarii, a Wayland client might allocate on any device. The Wayland compositor receiving the DMA-BUF has no clue where the buffer has been allocated from. The compositor will typically try to import the buffer into its "primary" device, although it would be capable of importing into any DRM device.

This causes issues in case buffer imports implicitly result in the buffer being moved to system memory. For instance, on a system with an Intel iGPU and an AMD dGPU, a client rendering with the dGPU and whose window is displayed on a screen connected to the dGPU would ideally not need any roundtrip to the iGPU. However, any attempt at figuring out where the DMA-BUF could be accessed from will move the buffer into system memory, degrading performance for the rest of the lifetime of the buffer.

Describing on which device the buffer has been allocated on is not enough: on some setups the buffer may have been allocated on one device but may still be directly accessible without any move on another device. For instance, on a split render/display system, a buffer allocated on the display device can be directly rendered to from the render device.

With this new flag, a compositor can try to import on all DRM devices without any side effects. If it finds a device which can access the buffer without a move, it can use that device to render the buffer. If it doesn't, it can fallback to the previous
behavior: try to import without the flag to the "primary" device, knowing this could result in a move to system memory.

This is a very incomplete implementation: it just checks whether the buffer was allocated from the main device it's imported to, and if not, passes a flag to dma_buf_attach() checked by i915 only. All other drivers need to be wired up, and the DMA-BUF API changes are just the first thing I could think of and unlikely to be the best design.

The goal of this RFC is to gather feedback: would the general idea of the new uAPI addition make sense to you? If so, do you see a better way to plumb it in the DMA-BUF framework?

Cc Sumit Semwal <[email protected]>
Cc Christian König <[email protected]>
Cc Daniel Stone <[email protected]>
Cc Victoria Brekenfeld <[email protected]>
Cc Michel Dänzer <[email protected]>
Cc Xaver Hugl <[email protected]>
Cc Simona Vetter <[email protected]>
Cc Austin Shafer <[email protected]>
---
 drivers/dma-buf/dma-buf.c                     | 11 ++++++--
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c   |  2 +-
 drivers/gpu/drm/drm_prime.c                   | 25 ++++++++++++++-----
 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c    |  9 +++++++
 drivers/gpu/drm/i915/gem/i915_gem_object.h    |  7 ++++++
 drivers/gpu/drm/xe/xe_dma_buf.c               |  2 +-
 drivers/infiniband/core/umem_dmabuf.c         |  3 ++-
 include/drm/drm_prime.h                       |  9 ++++---
 include/linux/dma-buf.h                       |  6 ++++-
 include/uapi/drm/drm.h                        |  3 ++-
 11 files changed, 62 insertions(+), 17 deletions(-)
drivers/dma-buf/dma-buf.c +9 -2
index fbbb750bc5b1..98ff03067fe7 100644
@@ -902,7 +902,7 @@ static struct sg_table * __map_dma_buf(struct dma_buf_attachment *attach,
 struct dma_buf_attachment *
 dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 		       const struct dma_buf_attach_ops *importer_ops,
-		       void *importer_priv)
+		       void *importer_priv, int flags)
 {
 	struct dma_buf_attachment *attach;
 	int ret;
@@ -925,6 +925,13 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 	attach->importer_priv = importer_priv;
 
 	if (dmabuf->ops->attach) {
+		if (DMA_BUF_ATTACH_NO_MOVE &&
+		    (!dmabuf->ops->attach_needs_move ||
+		      dmabuf->ops->attach_needs_move(dmabuf, attach))) {
+			ret = -EINVAL;
+			goto err_attach;
+		}
+
 		ret = dmabuf->ops->attach(dmabuf, attach);
 		if (ret)
 			goto err_attach;
@@ -989,7 +996,7 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_dynamic_attach, DMA_BUF);
 struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
 					  struct device *dev)
 {
-	return dma_buf_dynamic_attach(dmabuf, dev, NULL, NULL);
+	return dma_buf_dynamic_attach(dmabuf, dev, NULL, NULL, 0);
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_attach, DMA_BUF);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -1
index ce5ca304dba9..4059c9e114e1 100644
@@ -2452,7 +2452,7 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf_fd(struct amdgpu_device *adev, int fd,
 	int ret;
 
 	ret = drm_gem_prime_fd_to_handle(&adev->ddev, adev->kfd.client.file, fd,
-					 &handle);
+					 &handle, 0);
 	if (ret)
 		return ret;
 	obj = drm_gem_object_lookup(adev->kfd.client.file, handle);
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1 -1
index 8e81a83d37d8..ccda002b98f9 100644
@@ -430,7 +430,7 @@ struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
 		return obj;
 
 	attach = dma_buf_dynamic_attach(dma_buf, dev->dev,
-					&amdgpu_dma_buf_attach_ops, obj);
+					&amdgpu_dma_buf_attach_ops, obj, 0);
 	if (IS_ERR(attach)) {
 		drm_gem_object_put(obj);
 		return ERR_CAST(attach);
drivers/gpu/drm/drm_prime.c +19 -6
index 0e3f8adf162f..7207273c04fa 100644
@@ -294,7 +294,7 @@ EXPORT_SYMBOL(drm_gem_dmabuf_release);
  */
 int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 			       struct drm_file *file_priv, int prime_fd,
-			       uint32_t *handle)
+			       uint32_t *handle, uint32_t flags)
 {
 	struct dma_buf *dma_buf;
 	struct drm_gem_object *obj;
@@ -314,9 +314,10 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 	/* never seen this one, need to import */
 	mutex_lock(&dev->object_name_lock);
 	if (dev->driver->gem_prime_import)
+		/* TODO: pass flags around */
 		obj = dev->driver->gem_prime_import(dev, dma_buf);
 	else
-		obj = drm_gem_prime_import(dev, dma_buf);
+		obj = drm_gem_prime_import(dev, dma_buf, flags);
 	if (IS_ERR(obj)) {
 		ret = PTR_ERR(obj);
 		goto out_unlock;
@@ -368,11 +369,13 @@ int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
 	struct drm_prime_handle *args = data;
 
 	if (dev->driver->prime_fd_to_handle) {
+		/* TODO: pass around flags */
 		return dev->driver->prime_fd_to_handle(dev, file_priv, args->fd,
 						       &args->handle);
 	}
 
-	return drm_gem_prime_fd_to_handle(dev, file_priv, args->fd, &args->handle);
+	return drm_gem_prime_fd_to_handle(dev, file_priv, args->fd,
+					  &args->handle, args->flags);
 }
 
 static struct dma_buf *export_and_register_object(struct drm_device *dev,
@@ -636,6 +639,13 @@ void drm_gem_map_detach(struct dma_buf *dma_buf,
 }
 EXPORT_SYMBOL(drm_gem_map_detach);
 
+static int drm_gem_attach_needs_move(struct dma_buf *dma_buf,
+				     struct dma_buf_attachment *attach)
+{
+	/* TODO: is this correct for all drm_gem_prime_dmabuf_ops users? */
+	return 0;
+}
+
 /**
  * drm_gem_map_dma_buf - map_dma_buf implementation for GEM
  * @attach: attachment whose scatterlist is to be returned
@@ -813,6 +823,7 @@ static const struct dma_buf_ops drm_gem_prime_dmabuf_ops =  {
 	.cache_sgt_mapping = true,
 	.attach = drm_gem_map_attach,
 	.detach = drm_gem_map_detach,
+	.attach_needs_move = drm_gem_attach_needs_move,
 	.map_dma_buf = drm_gem_map_dma_buf,
 	.unmap_dma_buf = drm_gem_unmap_dma_buf,
 	.release = drm_gem_dmabuf_release,
@@ -933,7 +944,8 @@ EXPORT_SYMBOL(drm_gem_prime_export);
  */
 struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev,
 					    struct dma_buf *dma_buf,
-					    struct device *attach_dev)
+					    struct device *attach_dev,
+					    uint32_t flags)
 {
 	struct dma_buf_attachment *attach;
 	struct sg_table *sgt;
@@ -1002,9 +1014,10 @@ EXPORT_SYMBOL(drm_gem_prime_import_dev);
  * &drm_gem_object_funcs.free hook when using this function.
  */
 struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
-					    struct dma_buf *dma_buf)
+					    struct dma_buf *dma_buf,
+					    uint32_t flags)
 {
-	return drm_gem_prime_import_dev(dev, dma_buf, dev->dev);
+	return drm_gem_prime_import_dev(dev, dma_buf, dev->dev, flags);
 }
 EXPORT_SYMBOL(drm_gem_prime_import);
 
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +9 -0
index 1df74f7aa3dc..d88a307016a6 100644
@@ -201,9 +201,18 @@ static void i915_gem_dmabuf_detach(struct dma_buf *dmabuf,
 	i915_gem_object_unpin_pages(obj);
 }
 
+static int i915_gem_dmabuf_attach_needs_move(struct dma_buf *dmabuf,
+					     struct dma_buf_attachment *attach)
+{
+	struct drm_i915_gem_object *obj = dma_buf_to_obj(dmabuf);
+
+	return i915_gem_object_get_region_id(obj) != INTEL_REGION_SMEM;
+}
+
 static const struct dma_buf_ops i915_dmabuf_ops =  {
 	.attach = i915_gem_dmabuf_attach,
 	.detach = i915_gem_dmabuf_detach,
+	.attach_needs_move = i915_gem_dmabuf_attach_needs_move,
 	.map_dma_buf = i915_gem_map_dma_buf,
 	.unmap_dma_buf = drm_gem_unmap_dma_buf,
 	.release = drm_gem_dmabuf_release,
drivers/gpu/drm/i915/gem/i915_gem_object.h +7 -0
index 3dc61cbd2e11..f61637ada47a 100644
@@ -312,6 +312,13 @@ i915_gem_object_is_framebuffer(const struct drm_i915_gem_object *obj)
 	return READ_ONCE(obj->frontbuffer) || obj->is_dpt;
 }
 
+static inline enum intel_region_id
+i915_gem_object_get_region_id(const struct drm_i915_gem_object *obj)
+{
+	struct intel_memory_region *mr = READ_ONCE(obj->mm.region);
+	return mr->id;
+}
+
 static inline unsigned int
 i915_gem_object_get_tiling(const struct drm_i915_gem_object *obj)
 {
drivers/gpu/drm/xe/xe_dma_buf.c +1 -1
index 68f309f5e981..73bdc804ce0e 100644
@@ -296,7 +296,7 @@ struct drm_gem_object *xe_gem_prime_import(struct drm_device *dev,
 		attach_ops = test->attach_ops;
 #endif
 
-	attach = dma_buf_dynamic_attach(dma_buf, dev->dev, attach_ops, &bo->ttm.base);
+	attach = dma_buf_dynamic_attach(dma_buf, dev->dev, attach_ops, &bo->ttm.base, 0);
 	if (IS_ERR(attach)) {
 		obj = ERR_CAST(attach);
 		goto out_err;
drivers/infiniband/core/umem_dmabuf.c +2 -1
index 9fcd37761264..5ec4e90c80fd 100644
@@ -159,7 +159,8 @@ ib_umem_dmabuf_get_with_dma_device(struct ib_device *device,
 					dmabuf,
 					dma_device,
 					ops,
-					umem_dmabuf);
+					umem_dmabuf,
+					0);
 	if (IS_ERR(umem_dmabuf->attach)) {
 		ret = ERR_CAST(umem_dmabuf->attach);
 		goto out_free_umem;
include/drm/drm_prime.h +6 -3
index fa085c44d4ca..0dbf41564fdc 100644
@@ -68,7 +68,8 @@ struct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev,
 void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
 
 int drm_gem_prime_fd_to_handle(struct drm_device *dev,
-			       struct drm_file *file_priv, int prime_fd, uint32_t *handle);
+			       struct drm_file *file_priv, int prime_fd,
+			       uint32_t *handle, uint32_t flags);
 struct dma_buf *drm_gem_prime_handle_to_dmabuf(struct drm_device *dev,
 			       struct drm_file *file_priv, uint32_t handle,
 			       uint32_t flags);
@@ -102,9 +103,11 @@ unsigned long drm_prime_get_contiguous_size(struct sg_table *sgt);
 /* helper functions for importing */
 struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev,
 						struct dma_buf *dma_buf,
-						struct device *attach_dev);
+						struct device *attach_dev,
+						uint32_t flags);
 struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
-					    struct dma_buf *dma_buf);
+					    struct dma_buf *dma_buf,
+					    uint32_t flags);
 
 void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
 
include/linux/dma-buf.h +5 -1
index 36216d28d8bd..0fc7e059c934 100644
@@ -82,6 +82,8 @@ struct dma_buf_ops {
 	 */
 	void (*detach)(struct dma_buf *, struct dma_buf_attachment *);
 
+	int (*attach_needs_move)(struct dma_buf *, struct dma_buf_attachment *);
+
 	/**
 	 * @pin:
 	 *
@@ -597,12 +599,14 @@ dma_buf_attachment_is_dynamic(struct dma_buf_attachment *attach)
 	return !!attach->importer_ops;
 }
 
+#define DMA_BUF_ATTACH_NO_MOVE (1 << 0)
+
 struct dma_buf_attachment *dma_buf_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,
-		       void *importer_priv);
+		       void *importer_priv, int flags);
 void dma_buf_detach(struct dma_buf *dmabuf,
 		    struct dma_buf_attachment *attach);
 int dma_buf_pin(struct dma_buf_attachment *attach);
include/uapi/drm/drm.h +2 -1
index 7fba37b94401..9eec1d1c5a14 100644
@@ -883,10 +883,11 @@ struct drm_set_client_cap {
 
 #define DRM_RDWR O_RDWR
 #define DRM_CLOEXEC O_CLOEXEC
+#define DRM_PRIME_FD_TO_HANDLE_NO_MOVE (1 << 0)
 struct drm_prime_handle {
 	__u32 handle;
 
-	/** Flags.. only applicable for handle->fd */
+	/** Flags */
 	__u32 flags;
 
 	/** Returned dmabuf file descriptor */
Signature · 1 line
2.47.0
#1 lore raw
Quoted 26 lines · Simon Ser

This is a flag to opt-out of the automagic buffer migration to system memory when importing a DMA-BUF.

In multi-GPU scenarii, a Wayland client might allocate on any device. The Wayland compositor receiving the DMA-BUF has no clue where the buffer has been allocated from. The compositor will typically try to import the buffer into its "primary" device, although it would be capable of importing into any DRM device.

This causes issues in case buffer imports implicitly result in the buffer being moved to system memory. For instance, on a system with an Intel iGPU and an AMD dGPU, a client rendering with the dGPU and whose window is displayed on a screen connected to the dGPU would ideally not need any roundtrip to the iGPU. However, any attempt at figuring out where the DMA-BUF could be accessed from will move the buffer into system memory, degrading performance for the rest of the lifetime of the buffer.

Describing on which device the buffer has been allocated on is not enough: on some setups the buffer may have been allocated on one device but may still be directly accessible without any move on another device. For instance, on a split render/display system, a buffer allocated on the display device can be directly rendered to from the render device.

Quoted 6 lines

With this new flag, a compositor can try to import on all DRM devices without any side effects. If it finds a device which can access the buffer without a move, it can use that device to render the buffer. If it doesn't, it can fallback to the previous
behavior: try to import without the flag to the "primary" device, knowing this could result in a move to system memory.

One problem with this approach is that even if a buffer is originally created in / intended for local VRAM of a dGPU, it may get temporarily migrated to system RAM for other reasons, e.g. to make room for other buffers in VRAM. While it resides in system RAM, importing into another device with DRM_PRIME_FD_TO_HANDLE_NO_MOVE will work, but will result in pinning the buffer to system RAM, even though this isn't optimal for the intended buffer usage.

In other words, the new flag only gives the compositor information about the current state, not about the intention of the client. Another mechanism like https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/268 is needed for the latter.

So while this flag might be useful to prevent unintended buffer migration in some cases, it can't solve all multi-GPU issues for compositors.

Signature · 2 lines
Earthling Michel Dänzer       \        GNOME / Xwayland / Mesa developer
https://redhat.com             \               Libre software enthusiast
author
#2 lore raw
Quoted 28 lines · Michel Dänzer
Quoted 26 lines · Simon Ser

This is a flag to opt-out of the automagic buffer migration to system memory when importing a DMA-BUF.

In multi-GPU scenarii, a Wayland client might allocate on any device. The Wayland compositor receiving the DMA-BUF has no clue where the buffer has been allocated from. The compositor will typically try to import the buffer into its "primary" device, although it would be capable of importing into any DRM device.

This causes issues in case buffer imports implicitly result in the buffer being moved to system memory. For instance, on a system with an Intel iGPU and an AMD dGPU, a client rendering with the dGPU and whose window is displayed on a screen connected to the dGPU would ideally not need any roundtrip to the iGPU. However, any attempt at figuring out where the DMA-BUF could be accessed from will move the buffer into system memory, degrading performance for the rest of the lifetime of the buffer.

Describing on which device the buffer has been allocated on is not enough: on some setups the buffer may have been allocated on one device but may still be directly accessible without any move on another device. For instance, on a split render/display system, a buffer allocated on the display device can be directly rendered to from the render device.

Quoted 8 lines
Quoted 6 lines

With this new flag, a compositor can try to import on all DRM devices without any side effects. If it finds a device which can access the buffer without a move, it can use that device to render the buffer. If it doesn't, it can fallback to the previous
behavior: try to import without the flag to the "primary" device, knowing this could result in a move to system memory.

One problem with this approach is that even if a buffer is originally created in / intended for local VRAM of a dGPU, it may get temporarily migrated to system RAM for other reasons, e.g. to make room for other buffers in VRAM. While it resides in system RAM, importing into another device with DRM_PRIME_FD_TO_HANDLE_NO_MOVE will work, but will result in pinning the buffer to system RAM, even though this isn't optimal for the intended buffer usage.

Indeed. Do you think we could have a flag which also prevents pinning?

Sounds like that would involve implementing dynamic DMA-BUF importers in GEM? (Some drivers like xe already implement that.)

As a first step, a flag which checks whether the buffer comes from the same device it's imported from would be tremendously useful, even if that wouldn't work with split render/display systems. Ideally a new uAPI which can be extended to support such systems in the future would be great.

Quoted 3 lines

In other words, the new flag only gives the compositor information about the current state, not about the intention of the client. Another mechanism like https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/268 is needed for the latter.

So while this flag might be useful to prevent unintended buffer migration in some cases, it can't solve all multi-GPU issues for compositors.

I'm still not willing to give up on the idea that this doesn't need protocol changes in the long run, but maybe I'm being too optimistic here. :)

#3 lore raw
Quoted 37 lines · Simon Ser
Quoted 35 lines · Michel Dänzer
Quoted 32 lines · Simon Ser

This is a flag to opt-out of the automagic buffer migration to system memory when importing a DMA-BUF.

In multi-GPU scenarii, a Wayland client might allocate on any device. The Wayland compositor receiving the DMA-BUF has no clue where the buffer has been allocated from. The compositor will typically try to import the buffer into its "primary" device, although it would be capable of importing into any DRM device.

This causes issues in case buffer imports implicitly result in the buffer being moved to system memory. For instance, on a system with an Intel iGPU and an AMD dGPU, a client rendering with the dGPU and whose window is displayed on a screen connected to the dGPU would ideally not need any roundtrip to the iGPU. However, any attempt at figuring out where the DMA-BUF could be accessed from will move the buffer into system memory, degrading performance for the rest of the lifetime of the buffer.

Describing on which device the buffer has been allocated on is not enough: on some setups the buffer may have been allocated on one device but may still be directly accessible without any move on another device. For instance, on a split render/display system, a buffer allocated on the display device can be directly rendered to from the render device.

With this new flag, a compositor can try to import on all DRM devices without any side effects. If it finds a device which can access the buffer without a move, it can use that device to render the buffer. If it doesn't, it can fallback to the previous
behavior: try to import without the flag to the "primary" device, knowing this could result in a move to system memory.

Quoted 6 lines
Quoted 1 line

One problem with this approach is that even if a buffer is originally created in / intended for local VRAM of a dGPU, it may get temporarily migrated to system RAM for other reasons, e.g. to make room for other buffers in VRAM. While it resides in system RAM, importing into another device with DRM_PRIME_FD_TO_HANDLE_NO_MOVE will work, but will result in pinning the buffer to system RAM, even though this isn't optimal for the intended buffer usage.

Indeed. Do you think we could have a flag which also prevents pinning?

Sounds like that would involve implementing dynamic DMA-BUF importers in GEM? (Some drivers like xe already implement that.)

As discussed on IRC, that won't always help for the case I described. The exporting GPU will want to migrate the BO to its VRAM for drawing to it, the importing device might only be able to access it in system RAM though. The result would be migration ping-pong of the BO between VRAM and system RAM.

Taking a step back, I suspect something like "importing device can access while exporting device has optimal access" might be more useful than "can import without moving". Though that would still leave unknown if the importing device's access is optimal or not.

Signature · 2 lines
Earthling Michel Dänzer       \        GNOME / Xwayland / Mesa developer
https://redhat.com             \               Libre software enthusiast
#4 lore raw
In reply to Simon Ser
kernel test robot noticed the following build warnings:

Hi Simon,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on drm/drm-next]
[also build test WARNING on drm-exynos/exynos-drm-next linus/master v6.12-rc3 next-20241016] [cannot apply to drm-intel/for-linux-next drm-intel/for-linux-next-fixes drm-misc/drm-misc-next drm-tip/drm-tip] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Simon-Ser/drm-prime-introduce-DRM_PRIME_FD_TO_HANDLE_NO_MOVE/20241013-213609
base:   git://anongit.freedesktop.org/drm/drm drm-next
patch link:    https://lore.kernel.org/r/20241013133431.1356874-1-contact%40emersion.fr
patch subject: [RFC PATCH] drm/prime: introduce DRM_PRIME_FD_TO_HANDLE_NO_MOVE
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20241016/[email protected]/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241016/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/dma-buf/dma-buf.c:928:7: warning: converting the result of '<<' to a boolean always evaluates to true [-Wtautological-constant-compare]
     928 |                 if (DMA_BUF_ATTACH_NO_MOVE &&
         |                     ^
   include/linux/dma-buf.h:602:35: note: expanded from macro 'DMA_BUF_ATTACH_NO_MOVE'
     602 | #define DMA_BUF_ATTACH_NO_MOVE (1 << 0)
         |                                   ^

1 warning generated.

vim +928 drivers/dma-buf/dma-buf.c

815
816 /**
817 * DOC: locking convention
818 *
819 * In order to avoid deadlock situations between dma-buf exports and importers,
820 * all dma-buf API users must follow the common dma-buf locking convention.
821 *
822 * Convention for importers
823 *
824 * 1. Importers must hold the dma-buf reservation lock when calling these
825 * functions:
826 *

   827	 *     - dma_buf_pin()
   828	 *     - dma_buf_unpin()
   829	 *     - dma_buf_map_attachment()
   830	 *     - dma_buf_unmap_attachment()
   831	 *     - dma_buf_vmap()
   832	 *     - dma_buf_vunmap()
   833	 *
   834	 * 2. Importers must not hold the dma-buf reservation lock when calling these
   835	 *    functions:
   836	 *
   837	 *     - dma_buf_attach()
   838	 *     - dma_buf_dynamic_attach()
   839	 *     - dma_buf_detach()
   840	 *     - dma_buf_export()
   841	 *     - dma_buf_fd()
   842	 *     - dma_buf_get()
   843	 *     - dma_buf_put()
   844	 *     - dma_buf_mmap()
   845	 *     - dma_buf_begin_cpu_access()
   846	 *     - dma_buf_end_cpu_access()
   847	 *     - dma_buf_map_attachment_unlocked()
   848	 *     - dma_buf_unmap_attachment_unlocked()
   849	 *     - dma_buf_vmap_unlocked()
   850	 *     - dma_buf_vunmap_unlocked()
   851	 *
   852	 * Convention for exporters
   853	 *
   854	 * 1. These &dma_buf_ops callbacks are invoked with unlocked dma-buf
   855	 *    reservation and exporter can take the lock:
   856	 *
   857	 *     - &dma_buf_ops.attach()
   858	 *     - &dma_buf_ops.detach()
   859	 *     - &dma_buf_ops.release()
   860	 *     - &dma_buf_ops.begin_cpu_access()
   861	 *     - &dma_buf_ops.end_cpu_access()
   862	 *     - &dma_buf_ops.mmap()
   863	 *
   864	 * 2. These &dma_buf_ops callbacks are invoked with locked dma-buf
   865	 *    reservation and exporter can't take the lock:
   866	 *
   867	 *     - &dma_buf_ops.pin()
   868	 *     - &dma_buf_ops.unpin()
   869	 *     - &dma_buf_ops.map_dma_buf()
   870	 *     - &dma_buf_ops.unmap_dma_buf()
   871	 *     - &dma_buf_ops.vmap()
   872	 *     - &dma_buf_ops.vunmap()
   873	 *
   874	 * 3. Exporters must hold the dma-buf reservation lock when calling these
   875	 *    functions:
   876	 *
   877	 *     - dma_buf_move_notify()
   878	 */
   879	
   880	/**
   881	 * dma_buf_dynamic_attach - Add the device to dma_buf's attachments list
   882	 * @dmabuf:		[in]	buffer to attach device to.
   883	 * @dev:		[in]	device to be attached.
   884	 * @importer_ops:	[in]	importer operations for the attachment
   885	 * @importer_priv:	[in]	importer private pointer for the attachment
   886	 *
   887	 * Returns struct dma_buf_attachment pointer for this attachment. Attachments
   888	 * must be cleaned up by calling dma_buf_detach().
   889	 *
   890	 * Optionally this calls &dma_buf_ops.attach to allow device-specific attach
   891	 * functionality.
   892	 *
   893	 * Returns:
   894	 *
   895	 * A pointer to newly created &dma_buf_attachment on success, or a negative
   896	 * error code wrapped into a pointer on failure.
   897	 *
   898	 * Note that this can fail if the backing storage of @dmabuf is in a place not
   899	 * accessible to @dev, and cannot be moved to a more suitable place. This is
   900	 * indicated with the error code -EBUSY.
   901	 */
   902	struct dma_buf_attachment *
   903	dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
   904			       const struct dma_buf_attach_ops *importer_ops,
   905			       void *importer_priv, int flags)
   906	{
   907		struct dma_buf_attachment *attach;
   908		int ret;
   909	
   910		if (WARN_ON(!dmabuf || !dev))
   911			return ERR_PTR(-EINVAL);
   912	
   913		if (WARN_ON(importer_ops && !importer_ops->move_notify))
   914			return ERR_PTR(-EINVAL);
   915	
   916		attach = kzalloc(sizeof(*attach), GFP_KERNEL);
   917		if (!attach)
   918			return ERR_PTR(-ENOMEM);
   919	
   920		attach->dev = dev;
   921		attach->dmabuf = dmabuf;
   922		if (importer_ops)
   923			attach->peer2peer = importer_ops->allow_peer2peer;
   924		attach->importer_ops = importer_ops;
   925		attach->importer_priv = importer_priv;
   926	
   927		if (dmabuf->ops->attach) {
 > 928			if (DMA_BUF_ATTACH_NO_MOVE &&

929 (!dmabuf->ops->attach_needs_move ||
930 dmabuf->ops->attach_needs_move(dmabuf, attach))) {
931 ret = -EINVAL;
932 goto err_attach;
933 }
934
935 ret = dmabuf->ops->attach(dmabuf, attach);
936 if (ret)
937 goto err_attach;
938 }
939 dma_resv_lock(dmabuf->resv, NULL);
940 list_add(&attach->node, &dmabuf->attachments);
941 dma_resv_unlock(dmabuf->resv);
942
943 /* When either the importer or the exporter can't handle dynamic
944 * mappings we cache the mapping here to avoid issues with the
945 * reservation object lock.
946 */
947 if (dma_buf_attachment_is_dynamic(attach) !=
948 dma_buf_is_dynamic(dmabuf)) {
949 struct sg_table *sgt;
950
951 dma_resv_lock(attach->dmabuf->resv, NULL);
952 if (dma_buf_is_dynamic(attach->dmabuf)) {
953 ret = dmabuf->ops->pin(attach);
954 if (ret)
955 goto err_unlock;
956 }
957
958 sgt = __map_dma_buf(attach, DMA_BIDIRECTIONAL);
959 if (!sgt)
960 sgt = ERR_PTR(-ENOMEM);
961 if (IS_ERR(sgt)) {
962 ret = PTR_ERR(sgt);
963 goto err_unpin;
964 }
965 dma_resv_unlock(attach->dmabuf->resv);
966 attach->sgt = sgt;
967 attach->dir = DMA_BIDIRECTIONAL;
968 }
969
970 return attach;
971
972 err_attach:
973 kfree(attach);
974 return ERR_PTR(ret);
975
976 err_unpin:
977 if (dma_buf_is_dynamic(attach->dmabuf))
978 dmabuf->ops->unpin(attach);
979
980 err_unlock:
981 dma_resv_unlock(attach->dmabuf->resv);
982
983 dma_buf_detach(dmabuf, attach);
984 return ERR_PTR(ret);
985 }
986 EXPORT_SYMBOL_NS_GPL(dma_buf_dynamic_attach, DMA_BUF);
987

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw
In reply to Simon Ser
kernel test robot noticed the following build errors:

Hi Simon,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on drm/drm-next]
[also build test ERROR on drm-exynos/exynos-drm-next linus/master v6.12-rc3 next-20241016] [cannot apply to drm-intel/for-linux-next drm-intel/for-linux-next-fixes drm-misc/drm-misc-next drm-tip/drm-tip] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Simon-Ser/drm-prime-introduce-DRM_PRIME_FD_TO_HANDLE_NO_MOVE/20241013-213609
base:   git://anongit.freedesktop.org/drm/drm drm-next
patch link:    https://lore.kernel.org/r/20241013133431.1356874-1-contact%40emersion.fr
patch subject: [RFC PATCH] drm/prime: introduce DRM_PRIME_FD_TO_HANDLE_NO_MOVE
config: x86_64-rhel-8.3 (https://download.01.org/0day-ci/archive/20241016/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241016/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

>> drivers/dma-buf/dma-buf.c:906: warning: Function parameter or struct member 'flags' not described in 'dma_buf_dynamic_attach'
--
>> drivers/gpu/drm/drm_prime.c:298: warning: Function parameter or struct member 'flags' not described in 'drm_gem_prime_fd_to_handle'
>> drivers/gpu/drm/drm_prime.c:949: warning: Function parameter or struct member 'flags' not described in 'drm_gem_prime_import_dev'
>> drivers/gpu/drm/drm_prime.c:1019: warning: Function parameter or struct member 'flags' not described in 'drm_gem_prime_import'
--
   drivers/gpu/drm/vmwgfx/vmwgfx_surface.c: In function 'vmw_buffer_prime_to_surface_base':
>> drivers/gpu/drm/vmwgfx/vmwgfx_surface.c:974:15: error: too few arguments to function 'drm_gem_prime_fd_to_handle'
     974 |         ret = drm_gem_prime_fd_to_handle(&dev_priv->drm, file_priv, fd, handle);
         |               ^~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from include/drm/drm_file.h:39,
from drivers/gpu/drm/vmwgfx/vmwgfx_drv.h:38, from drivers/gpu/drm/vmwgfx/vmwgfx_surface.c:30:
include/drm/drm_prime.h:70:5: note: declared here
70 | int drm_gem_prime_fd_to_handle(struct drm_device *dev,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
--
drivers/gpu/drm/vmwgfx/vmwgfx_prime.c: In function 'vmw_prime_fd_to_handle':

>> drivers/gpu/drm/vmwgfx/vmwgfx_prime.c:83:23: error: too few arguments to function 'drm_gem_prime_fd_to_handle'
      83 |                 ret = drm_gem_prime_fd_to_handle(dev, file_priv, fd, handle);
         |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from include/drm/drm_file.h:39,
from drivers/gpu/drm/vmwgfx/vmwgfx_drv.h:38,
from drivers/gpu/drm/vmwgfx/vmwgfx_prime.c:34:
include/drm/drm_prime.h:70:5: note: declared here
70 | int drm_gem_prime_fd_to_handle(struct drm_device *dev,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
--
drivers/gpu/drm/virtio/virtgpu_prime.c: In function 'virtgpu_gem_prime_import':

>> drivers/gpu/drm/virtio/virtgpu_prime.c:162:16: error: too few arguments to function 'drm_gem_prime_import'
     162 |         return drm_gem_prime_import(dev, buf);
         |                ^~~~~~~~~~~~~~~~~~~~
   In file included from drivers/gpu/drm/virtio/virtgpu_prime.c:25:
   include/drm/drm_prime.h:108:24: note: declared here
     108 | struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
         |                        ^~~~~~~~~~~~~~~~~~~~
>> drivers/gpu/drm/virtio/virtgpu_prime.c:163:1: warning: control reaches end of non-void function [-Wreturn-type]
     163 | }
         | ^

vim +/drm_gem_prime_fd_to_handle +974 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c

d6667f0ddf46c6 Zack Rusin       2024-07-22   962  
d6667f0ddf46c6 Zack Rusin       2024-07-22   963  static int vmw_buffer_prime_to_surface_base(struct vmw_private *dev_priv,
d6667f0ddf46c6 Zack Rusin       2024-07-22   964  					    struct drm_file *file_priv,
d6667f0ddf46c6 Zack Rusin       2024-07-22   965  					    u32 fd, u32 *handle,
d6667f0ddf46c6 Zack Rusin       2024-07-22   966  					    struct ttm_base_object **base_p)
d6667f0ddf46c6 Zack Rusin       2024-07-22   967  {
d6667f0ddf46c6 Zack Rusin       2024-07-22   968  	struct ttm_base_object *base;
d6667f0ddf46c6 Zack Rusin       2024-07-22   969  	struct vmw_bo *bo;
d6667f0ddf46c6 Zack Rusin       2024-07-22   970  	struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
d6667f0ddf46c6 Zack Rusin       2024-07-22   971  	struct vmw_user_surface *user_srf;
d6667f0ddf46c6 Zack Rusin       2024-07-22   972  	int ret;
d6667f0ddf46c6 Zack Rusin       2024-07-22   973  
d6667f0ddf46c6 Zack Rusin       2024-07-22  @974  	ret = drm_gem_prime_fd_to_handle(&dev_priv->drm, file_priv, fd, handle);
d6667f0ddf46c6 Zack Rusin       2024-07-22   975  	if (ret) {
d6667f0ddf46c6 Zack Rusin       2024-07-22   976  		drm_warn(&dev_priv->drm,
d6667f0ddf46c6 Zack Rusin       2024-07-22   977  			 "Wasn't able to find user buffer for fd = %u.\n", fd);
d6667f0ddf46c6 Zack Rusin       2024-07-22   978  		return ret;
d6667f0ddf46c6 Zack Rusin       2024-07-22   979  	}
d6667f0ddf46c6 Zack Rusin       2024-07-22   980  
d6667f0ddf46c6 Zack Rusin       2024-07-22   981  	ret = vmw_user_bo_lookup(file_priv, *handle, &bo);
d6667f0ddf46c6 Zack Rusin       2024-07-22   982  	if (ret) {
d6667f0ddf46c6 Zack Rusin       2024-07-22   983  		drm_warn(&dev_priv->drm,
d6667f0ddf46c6 Zack Rusin       2024-07-22   984  			 "Wasn't able to lookup user buffer for handle = %u.\n", *handle);
d6667f0ddf46c6 Zack Rusin       2024-07-22   985  		return ret;
d6667f0ddf46c6 Zack Rusin       2024-07-22   986  	}
d6667f0ddf46c6 Zack Rusin       2024-07-22   987  
d6667f0ddf46c6 Zack Rusin       2024-07-22   988  	user_srf = vmw_lookup_user_surface_for_buffer(dev_priv, bo, *handle);
d6667f0ddf46c6 Zack Rusin       2024-07-22   989  	if (WARN_ON(!user_srf)) {
d6667f0ddf46c6 Zack Rusin       2024-07-22   990  		drm_warn(&dev_priv->drm,
d6667f0ddf46c6 Zack Rusin       2024-07-22   991  			 "User surface fd %d (handle %d) is null.\n", fd, *handle);
d6667f0ddf46c6 Zack Rusin       2024-07-22   992  		ret = -EINVAL;
d6667f0ddf46c6 Zack Rusin       2024-07-22   993  		goto out;
d6667f0ddf46c6 Zack Rusin       2024-07-22   994  	}
d6667f0ddf46c6 Zack Rusin       2024-07-22   995  
d6667f0ddf46c6 Zack Rusin       2024-07-22   996  	base = &user_srf->prime.base;
d6667f0ddf46c6 Zack Rusin       2024-07-22   997  	ret = ttm_ref_object_add(tfile, base, NULL, false);
d6667f0ddf46c6 Zack Rusin       2024-07-22   998  	if (ret) {
d6667f0ddf46c6 Zack Rusin       2024-07-22   999  		drm_warn(&dev_priv->drm,
d6667f0ddf46c6 Zack Rusin       2024-07-22  1000  			 "Couldn't add an object ref for the buffer (%d).\n", *handle);
d6667f0ddf46c6 Zack Rusin       2024-07-22  1001  		goto out;
d6667f0ddf46c6 Zack Rusin       2024-07-22  1002  	}
d6667f0ddf46c6 Zack Rusin       2024-07-22  1003  
d6667f0ddf46c6 Zack Rusin       2024-07-22  1004  	*base_p = base;
d6667f0ddf46c6 Zack Rusin       2024-07-22  1005  out:
d6667f0ddf46c6 Zack Rusin       2024-07-22  1006  	vmw_user_bo_unref(&bo);
d6667f0ddf46c6 Zack Rusin       2024-07-22  1007  
d6667f0ddf46c6 Zack Rusin       2024-07-22  1008  	return ret;
d6667f0ddf46c6 Zack Rusin       2024-07-22  1009  }

adebcb20e4ca93 Thomas Hellstrom 2014-03-18 1010

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki