All of lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-xe] [PATCH v2] drm/xe: Disallow pinning dma-bufs in VRAM
@ 2023-09-20  9:50 Thomas Hellström
  2023-09-20 10:31 ` [Intel-xe] ✓ CI.Patch_applied: success for drm/xe: Disallow pinning dma-bufs in VRAM (rev2) Patchwork
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Thomas Hellström @ 2023-09-20  9:50 UTC (permalink / raw)
  To: intel-xe

For now only support pinning in TT memory, for two reasons:
1) Avoid pinning in a placement not accessible to some importers.
2) Pinning in VRAM requires PIN accounting which is a to-do.

v2:
- Adjust the dma-buf kunit test accordingly.

Suggested-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
---
 drivers/gpu/drm/xe/tests/xe_dma_buf.c | 16 ++++++++++++----
 drivers/gpu/drm/xe/xe_dma_buf.c       | 25 +++++++++++++++++++++----
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/xe/tests/xe_dma_buf.c b/drivers/gpu/drm/xe/tests/xe_dma_buf.c
index 1c3f4bc72b99..ee911df94cc9 100644
--- a/drivers/gpu/drm/xe/tests/xe_dma_buf.c
+++ b/drivers/gpu/drm/xe/tests/xe_dma_buf.c
@@ -150,11 +150,19 @@ static void xe_test_dmabuf_import_same_driver(struct xe_device *xe)
 			/* Is everything where we expect it to be? */
 			xe_bo_lock(import_bo, false);
 			err = xe_bo_validate(import_bo, NULL, false);
-			if (err && err != -EINTR && err != -ERESTARTSYS)
-				KUNIT_FAIL(test,
-					   "xe_bo_validate() failed with err=%d\n", err);
 
-			check_residency(test, bo, import_bo, dmabuf);
+			/* Pinning in VRAM is not allowed. */
+			if (!is_dynamic(params) &&
+			    params->force_different_devices &&
+			    !(params->mem_mask & XE_BO_CREATE_SYSTEM_BIT))
+				KUNIT_EXPECT_EQ(test, err, -EINVAL);
+			/* Otherwise only expect interrupts or success. */
+			else if (err && err != -EINTR && err != -ERESTARTSYS)
+				KUNIT_EXPECT_TRUE(test, !err || err == -EINTR ||
+						  err == -ERESTARTSYS);
+
+			if (!err)
+				check_residency(test, bo, import_bo, dmabuf);
 			xe_bo_unlock(import_bo);
 		}
 		drm_gem_object_put(import);
diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c
index 09343b8b3e96..bd8d51e7f93f 100644
--- a/drivers/gpu/drm/xe/xe_dma_buf.c
+++ b/drivers/gpu/drm/xe/xe_dma_buf.c
@@ -49,13 +49,30 @@ static int xe_dma_buf_pin(struct dma_buf_attachment *attach)
 {
 	struct drm_gem_object *obj = attach->dmabuf->priv;
 	struct xe_bo *bo = gem_to_xe_bo(obj);
+	struct xe_device *xe = xe_bo_device(bo);
+	int ret;
 
 	/*
-	 * Migrate to TT first to increase the chance of non-p2p clients
-	 * can attach.
+	 * For now only support pinning in TT memory, for two reasons:
+	 * 1) Avoid pinning in a placement not accessible to some importers.
+	 * 2) Pinning in VRAM requires PIN accounting which is a to-do.
 	 */
-	(void)xe_bo_migrate(bo, XE_PL_TT);
-	xe_bo_pin_external(bo);
+	if (xe_bo_is_pinned(bo) && bo->ttm.resource->placement != XE_PL_TT) {
+		drm_dbg(&xe->drm, "Can't migrate pinned bo for dma-buf pin.\n");
+		return -EINVAL;
+	}
+
+	ret = xe_bo_migrate(bo, XE_PL_TT);
+	if (ret) {
+		if (ret != -EINTR && ret != -ERESTARTSYS)
+			drm_dbg(&xe->drm,
+				"Failed migrating dma-buf to TT memory: %pe\n",
+				ERR_PTR(ret));
+		return ret;
+	}
+
+	ret = xe_bo_pin_external(bo);
+	xe_assert(xe, !ret);
 
 	return 0;
 }
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-09-20 12:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-20  9:50 [Intel-xe] [PATCH v2] drm/xe: Disallow pinning dma-bufs in VRAM Thomas Hellström
2023-09-20 10:31 ` [Intel-xe] ✓ CI.Patch_applied: success for drm/xe: Disallow pinning dma-bufs in VRAM (rev2) Patchwork
2023-09-20 10:31 ` [Intel-xe] ✓ CI.checkpatch: " Patchwork
2023-09-20 10:33 ` [Intel-xe] ✓ CI.KUnit: " Patchwork
2023-09-20 10:40 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-09-20 10:40 ` [Intel-xe] ✓ CI.Hooks: " Patchwork
2023-09-20 10:41 ` [Intel-xe] ✓ CI.checksparse: " Patchwork
2023-09-20 11:16 ` [Intel-xe] ✓ CI.BAT: " Patchwork
2023-09-20 12:35 ` [Intel-xe] [PATCH v2] drm/xe: Disallow pinning dma-bufs in VRAM Thomas Hellström

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.