Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: matthew.auld@intel.com, thomas.hellstrom@linux.intel.com
Subject: [PATCH v3 6/6] drm/xe: Only allow contiguous BOs to use xe_bo_vmap
Date: Sat, 19 Oct 2024 12:20:30 -0700	[thread overview]
Message-ID: <20241019192030.1505020-7-matthew.brost@intel.com> (raw)
In-Reply-To: <20241019192030.1505020-1-matthew.brost@intel.com>

xe_bo_vmap only works on contiguous BOs, disallow xe_bo_vmap on BO
unless we are certain the BO is contiguous.

Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
 drivers/gpu/drm/xe/xe_bo.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 0a7b91df69c2..46c640f8db9e 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -162,6 +162,15 @@ static void try_add_system(struct xe_device *xe, struct xe_bo *bo,
 	}
 }
 
+static bool force_contiguous(u32 bo_flags)
+{
+	/*
+	 * For eviction / restore on suspend / resume objects pinned in VRAM
+	 * must be contiguous, also only contiguous BOs support xe_bo_vmap.
+	 */
+	return bo_flags & (XE_BO_FLAG_PINNED | XE_BO_FLAG_GGTT);
+}
+
 static void add_vram(struct xe_device *xe, struct xe_bo *bo,
 		     struct ttm_place *places, u32 bo_flags, u32 mem_type, u32 *c)
 {
@@ -175,12 +184,7 @@ static void add_vram(struct xe_device *xe, struct xe_bo *bo,
 	xe_assert(xe, vram && vram->usable_size);
 	io_size = vram->io_size;
 
-	/*
-	 * For eviction / restore on suspend / resume objects
-	 * pinned in VRAM must be contiguous
-	 */
-	if (bo_flags & (XE_BO_FLAG_PINNED |
-			XE_BO_FLAG_GGTT))
+	if (force_contiguous(bo_flags))
 		place.flags |= TTM_PL_FLAG_CONTIGUOUS;
 
 	if (io_size < vram->usable_size) {
@@ -212,8 +216,7 @@ static void try_add_stolen(struct xe_device *xe, struct xe_bo *bo,
 
 		bo->placements[*c] = (struct ttm_place) {
 			.mem_type = XE_PL_STOLEN,
-			.flags = bo_flags & (XE_BO_FLAG_PINNED |
-					     XE_BO_FLAG_GGTT) ?
+			.flags = force_contiguous(bo_flags) ?
 				TTM_PL_FLAG_CONTIGUOUS : 0,
 		};
 		*c += 1;
@@ -2024,13 +2027,15 @@ dma_addr_t xe_bo_addr(struct xe_bo *bo, u64 offset, size_t page_size)
 
 int xe_bo_vmap(struct xe_bo *bo)
 {
+	struct xe_device *xe = ttm_to_xe_device(bo->ttm.bdev);
 	void *virtual;
 	bool is_iomem;
 	int ret;
 
 	xe_bo_assert_held(bo);
 
-	if (!(bo->flags & XE_BO_FLAG_NEEDS_CPU_ACCESS))
+	if (drm_WARN_ON(&xe->drm, !(bo->flags & XE_BO_FLAG_NEEDS_CPU_ACCESS) ||
+			!force_contiguous(bo->flags)))
 		return -EINVAL;
 
 	if (!iosys_map_is_null(&bo->vmap))
-- 
2.34.1


  parent reply	other threads:[~2024-10-19 19:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-19 19:20 [PATCH v3 0/6] Fix non-contiguous VRAM BO access in Xe Matthew Brost
2024-10-19 19:20 ` [PATCH v3 1/6] drm/ttm: Add ttm_bo_access Matthew Brost
2024-10-19 19:20 ` [PATCH v3 2/6] drm/xe: Add xe_ttm_access_memory Matthew Brost
2024-10-19 19:20 ` [PATCH v3 3/6] drm/xe: Update xe_ttm_access_memory to use GPU for non-visible access Matthew Brost
2024-10-21 10:15   ` Matthew Auld
2024-10-21 11:01     ` Thomas Hellström
2024-10-21 17:18       ` Matthew Brost
2024-10-21 17:02     ` Matthew Brost
2024-10-19 19:20 ` [PATCH v3 4/6] drm/xe: Use ttm_bo_access in xe_vm_snapshot_capture_delayed Matthew Brost
2024-10-21  9:07   ` Matthew Auld
2024-10-21 16:58     ` Matthew Brost
2024-10-19 19:20 ` [PATCH v3 5/6] drm/xe: Set XE_BO_FLAG_PINNED in migrate selftest BOs Matthew Brost
2024-10-21  9:50   ` Matthew Auld
2024-10-19 19:20 ` Matthew Brost [this message]
2024-10-21  9:32   ` [PATCH v3 6/6] drm/xe: Only allow contiguous BOs to use xe_bo_vmap Matthew Auld
2024-10-19 19:25 ` ✓ CI.Patch_applied: success for Fix non-contiguous VRAM BO access in Xe (rev3) Patchwork
2024-10-19 19:25 ` ✗ CI.checkpatch: warning " Patchwork
2024-10-19 19:27 ` ✓ CI.KUnit: success " Patchwork
2024-10-19 19:38 ` ✓ CI.Build: " Patchwork
2024-10-19 19:40 ` ✓ CI.Hooks: " Patchwork
2024-10-19 19:42 ` ✗ CI.checksparse: warning " Patchwork
2024-10-19 20:07 ` ✓ CI.BAT: success " Patchwork
2024-10-19 21:06 ` ✗ CI.FULL: failure " 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=20241019192030.1505020-7-matthew.brost@intel.com \
    --to=matthew.brost@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.auld@intel.com \
    --cc=thomas.hellstrom@linux.intel.com \
    /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