From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: intel-xe@lists.freedesktop.org
Subject: [Intel-xe] [PATCH] drm/xe: Disallow pinning dma-bufs in VRAM
Date: Tue, 19 Sep 2023 10:46:09 +0200 [thread overview]
Message-ID: <20230919084609.15768-1-thomas.hellstrom@linux.intel.com> (raw)
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.
Suggested-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
drivers/gpu/drm/xe/xe_dma_buf.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
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
next reply other threads:[~2023-09-19 8:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-19 8:46 Thomas Hellström [this message]
2023-09-19 9:22 ` [Intel-xe] ✓ CI.Patch_applied: success for drm/xe: Disallow pinning dma-bufs in VRAM Patchwork
2023-09-19 9:23 ` [Intel-xe] ✓ CI.checkpatch: " Patchwork
2023-09-19 9:24 ` [Intel-xe] ✓ CI.KUnit: " Patchwork
2023-09-19 9:31 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-09-19 9:31 ` [Intel-xe] ✓ CI.Hooks: " Patchwork
2023-09-19 9:32 ` [Intel-xe] ✓ CI.checksparse: " Patchwork
2023-09-19 10:04 ` [Intel-xe] ✓ CI.BAT: " Patchwork
2023-09-20 9:35 ` [Intel-xe] [PATCH] " Oded Gabbay
2023-09-20 9:51 ` Thomas Hellström
2023-09-20 9:53 ` Oded Gabbay
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=20230919084609.15768-1-thomas.hellstrom@linux.intel.com \
--to=thomas.hellstrom@linux.intel.com \
--cc=intel-xe@lists.freedesktop.org \
/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