From: Matthew Auld <matthew.auld@intel.com>
To: intel-xe@lists.freedesktop.org
Subject: [Intel-xe] [PATCH v3 3/3] drm/xe/bo: sync kernel fences for KMD buffers
Date: Mon, 30 Oct 2023 16:10:20 +0000 [thread overview]
Message-ID: <20231030161016.54300-8-matthew.auld@intel.com> (raw)
In-Reply-To: <20231030161016.54300-5-matthew.auld@intel.com>
With things like pipelined evictions, VRAM pages can be marked as free
and yet still have some active kernel fences, with the idea that the
next caller to allocate the memory will respect them. However it looks
like we are missing synchronisation for KMD internal buffers, like
page-tables, lrc etc. For userspace objects we should already have the
required synchronisation for CPU access via the fault handler, and
likewise for GPU access when vm_binding them.
To fix this synchronise against any kernel fences for all KMD objects at
creation. This should resolve some severe corruption seen during
evictions.
v2 (Matt B):
- Revamp the comment explaining this. Also mention why USAGE_KERNEL is
correct here.
v3 (Thomas):
- Make sure to use ctx.interruptible for the wait.
Closes: ?
Testcase: igt@xe-evict-ccs
Reported-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 61789c0e88fb..cd043b1308ec 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -1266,6 +1266,37 @@ struct xe_bo *__xe_bo_create_locked(struct xe_device *xe, struct xe_bo *bo,
if (err)
return ERR_PTR(err);
+ /*
+ * The VRAM pages underneath are potentially still being accessed by the
+ * GPU, as per async GPU clearing and async evictions. However TTM makes
+ * sure to add any corresponding move/clear fences into the objects
+ * dma-resv using the DMA_RESV_USAGE_KERNEL slot.
+ *
+ * For KMD internal buffers we don't care about GPU clearing, however we
+ * still need to handle async evictions, where the VRAM is still being
+ * accessed by the GPU. Most internal callers are not expecting this,
+ * since they are missing the required synchronisation before accessing
+ * the memory. To keep things simple just sync wait any kernel fences
+ * here, if the buffer is designated KMD internal.
+ *
+ * For normal userspace objects we should already have the required
+ * pipelining or sync waiting elsewhere, since we already have to deal
+ * with things like async GPU clearing.
+ */
+ if (type == ttm_bo_type_kernel) {
+ long timeout = dma_resv_wait_timeout(bo->ttm.base.resv,
+ DMA_RESV_USAGE_KERNEL,
+ ctx.interruptible,
+ MAX_SCHEDULE_TIMEOUT);
+
+ if (timeout < 0) {
+ if (!resv)
+ dma_resv_unlock(bo->ttm.base.resv);
+ xe_bo_put(bo);
+ return ERR_PTR(timeout);
+ }
+ }
+
bo->created = true;
if (bulk)
ttm_bo_set_bulk_move(&bo->ttm, bulk);
--
2.41.0
next prev parent reply other threads:[~2023-10-30 16:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-30 16:10 [Intel-xe] [PATCH v3 0/3] Some eviction fixes Matthew Auld
2023-10-30 16:10 ` [Intel-xe] [PATCH v3 1/3] drm/xe/migrate: fix MI_ARB_ON_OFF usage Matthew Auld
2023-10-30 16:10 ` [Intel-xe] [PATCH v3 2/3] drm/xe/bo: consider dma-resv fences for clear job Matthew Auld
2023-10-30 16:10 ` Matthew Auld [this message]
2023-10-30 16:13 ` [Intel-xe] [PATCH v3 3/3] drm/xe/bo: sync kernel fences for KMD buffers Thomas Hellström
2023-10-30 17:06 ` [Intel-xe] ✓ CI.Patch_applied: success for Some eviction fixes (rev3) Patchwork
2023-10-30 17:06 ` [Intel-xe] ✗ CI.checkpatch: warning " Patchwork
2023-10-30 17:07 ` [Intel-xe] ✓ CI.KUnit: success " Patchwork
2023-10-30 17:14 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-10-30 17:15 ` [Intel-xe] ✓ CI.Hooks: " Patchwork
2023-10-30 17:16 ` [Intel-xe] ✓ CI.checksparse: " Patchwork
2023-10-30 17:45 ` [Intel-xe] ✗ CI.BAT: failure " Patchwork
2023-10-31 8:17 ` [Intel-xe] ✓ CI.Patch_applied: success for Some eviction fixes (rev4) Patchwork
2023-10-31 8:17 ` [Intel-xe] ✗ CI.checkpatch: warning " Patchwork
2023-10-31 8:19 ` [Intel-xe] ✓ CI.KUnit: success " Patchwork
2023-10-31 8:26 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-10-31 8:26 ` [Intel-xe] ✓ CI.Hooks: " Patchwork
2023-10-31 8:27 ` [Intel-xe] ✓ CI.checksparse: " Patchwork
2023-10-31 9:09 ` [Intel-xe] ✓ CI.BAT: " Patchwork
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=20231030161016.54300-8-matthew.auld@intel.com \
--to=matthew.auld@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 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.