Skip to contentSkip to conversation

Rework TTMs busy handling

PATCH In review Christian König 7 participants 22 messages Jan 12, 2024 – Jan 29, 2024

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

Hi guys,

same as the last time. Things I've changed:

Implemented the requirements from Zack to correctly fill in the busy placements for VMWGFX.

Renamed the placement flags to desired and fallback as suggested by Michel.

Rebased on drm-tip instead of drm-misc-next and fixed XE as well.

Please review and comment,
Christian.

#1 lore raw

PATCH 1/5 drm/vmwgfx: remove vmw_vram_gmr_placement

Seems to be unused.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h        |  1 -
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 28 ----------------------
 2 files changed, 29 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +0 -1
index 3cd5090dedfc..12efecc17df6 100644
@@ -942,7 +942,6 @@ vmw_is_cursor_bypass3_enabled(const struct vmw_private *dev_priv)
 
 extern const size_t vmw_tt_size;
 extern struct ttm_placement vmw_vram_placement;
-extern struct ttm_placement vmw_vram_gmr_placement;
 extern struct ttm_placement vmw_sys_placement;
 extern struct ttm_device_funcs vmw_bo_driver;
 extern const struct vmw_sg_table *
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +0 -28
index af8562c95cc3..a84fffcef8e1 100644
@@ -43,13 +43,6 @@ static const struct ttm_place sys_placement_flags = {
 	.flags = 0
 };
 
-static const struct ttm_place gmr_placement_flags = {
-	.fpfn = 0,
-	.lpfn = 0,
-	.mem_type = VMW_PL_GMR,
-	.flags = 0
-};
-
 struct ttm_placement vmw_vram_placement = {
 	.num_placement = 1,
 	.placement = &vram_placement_flags,
@@ -57,27 +50,6 @@ struct ttm_placement vmw_vram_placement = {
 	.busy_placement = &vram_placement_flags
 };
 
-static const struct ttm_place vram_gmr_placement_flags[] = {
-	{
-		.fpfn = 0,
-		.lpfn = 0,
-		.mem_type = TTM_PL_VRAM,
-		.flags = 0
-	}, {
-		.fpfn = 0,
-		.lpfn = 0,
-		.mem_type = VMW_PL_GMR,
-		.flags = 0
-	}
-};
-
-struct ttm_placement vmw_vram_gmr_placement = {
-	.num_placement = 2,
-	.placement = vram_gmr_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &gmr_placement_flags
-};
-
 struct ttm_placement vmw_sys_placement = {
 	.num_placement = 1,
 	.placement = &sys_placement_flags,
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/5 drm/ttm: return ENOSPC from ttm_bo_mem_space

In reply to Christian König

Only convert it to ENOMEM in ttm_bo_validate.

This allows ttm_bo_validate to distinct between an out of memory situation and just out of space in a placement domain.

---
 drivers/gpu/drm/ttm/ttm_bo.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo.c +4 -1
index edf10618fe2b..8c1eaa74fa21 100644
@@ -830,7 +830,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 			goto error;
 	}
 
-	ret = -ENOMEM;
+	ret = -ENOSPC;
 	if (!type_found) {
 		pr_err(TTM_PFX "No compatible memory type found\n");
 		ret = -EINVAL;
@@ -916,6 +916,9 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
 		return -EINVAL;
 
 	ret = ttm_bo_move_buffer(bo, placement, ctx);
+	/* For backward compatibility with userspace */
+	if (ret == -ENOSPC)
+		return -ENOMEM;
 	if (ret)
 		return ret;
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 2/5
#3 lore raw

Re: [PATCH 2/5] drm/ttm: return ENOSPC from ttm_bo_mem_space

Hi,

Quoted 3 lines · Christian König

Only convert it to ENOMEM in ttm_bo_validate.

This allows ttm_bo_validate to distinct between an out of memory

NIT: s/distinct/distinguish/

Quoted 1 line

situation and just out of space in a placement domain.

In fact it would be nice if this could be propagated back to drivers as well at some point, but then perhaps guarded with a flag in the operation context.

In any case

Quoted 29 lines
---
  drivers/gpu/drm/ttm/ttm_bo.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo.c +4 -1
index edf10618fe2b..8c1eaa74fa21 100644
@@ -830,7 +830,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
  			goto error;
  	}
 
-	ret = -ENOMEM;
+	ret = -ENOSPC;
  	if (!type_found) {
  		pr_err(TTM_PFX "No compatible memory type found\n");
  		ret = -EINVAL;
@@ -916,6 +916,9 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
  		return -EINVAL;
 
  	ret = ttm_bo_move_buffer(bo, placement, ctx);
+	/* For backward compatibility with userspace */
+	if (ret == -ENOSPC)
+		return -ENOMEM;
  	if (ret)
  		return ret;
 
#4 lore raw

PATCH 3/5 drm/ttm: replace busy placement with flags v6

In reply to Christian König

From: Somalapuram Amaranath <[email protected]>

Instead of a list of separate busy placement add flags which indicate that a placement should only be used when there is room or if we need to evict.

v2: add missing TTM_PL_FLAG_IDLE for i915
v3: fix auto build test ERROR on drm-tip/drm-tip
v4: fix some typos pointed out by checkpatch
v5: cleanup some rebase problems with VMWGFX
v6: implement some missing VMWGFX functionality pointed out by Zack,
rename the flags as suggested by Michel, rebase on drm-tip and adjust XE as well

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |  6 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 11 +---
 drivers/gpu/drm/drm_gem_vram_helper.c      |  2 -
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c    | 37 +++++------
 drivers/gpu/drm/loongson/lsdc_ttm.c        |  2 -
 drivers/gpu/drm/nouveau/nouveau_bo.c       | 59 +++++++----------
 drivers/gpu/drm/nouveau/nouveau_bo.h       |  1 -
 drivers/gpu/drm/qxl/qxl_object.c           |  2 -
 drivers/gpu/drm/qxl/qxl_ttm.c              |  2 -
 drivers/gpu/drm/radeon/radeon_object.c     |  2 -
 drivers/gpu/drm/radeon/radeon_ttm.c        |  8 +--
 drivers/gpu/drm/radeon/radeon_uvd.c        |  1 -
 drivers/gpu/drm/ttm/ttm_bo.c               | 21 ++++---
 drivers/gpu/drm/ttm/ttm_resource.c         | 73 +++++-----------------
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c         | 33 +++++++---
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c |  4 --
 drivers/gpu/drm/xe/xe_bo.c                 | 33 +++++-----
 include/drm/ttm/ttm_placement.h            | 10 +--
 include/drm/ttm/ttm_resource.h             |  8 +--
 19 files changed, 118 insertions(+), 197 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -5
index 425cebcc5cbf..b671b0665492 100644
@@ -220,9 +220,6 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain)
 
 	placement->num_placement = c;
 	placement->placement = places;
-
-	placement->num_busy_placement = c;
-	placement->busy_placement = places;
 }
 
 /**
@@ -1397,8 +1394,7 @@ vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
 					AMDGPU_GEM_DOMAIN_GTT);
 
 	/* Avoid costly evictions; only set GTT as a busy placement */
-	abo->placement.num_busy_placement = 1;
-	abo->placement.busy_placement = &abo->placements[1];
+	abo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
 
 	r = ttm_bo_validate(bo, &abo->placement, &ctx);
 	if (unlikely(r == -EBUSY || r == -ERESTARTSYS))
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -9
index 75c9fd2c6c2a..8722beba494e 100644
@@ -102,23 +102,19 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
 	/* Don't handle scatter gather BOs */
 	if (bo->type == ttm_bo_type_sg) {
 		placement->num_placement = 0;
-		placement->num_busy_placement = 0;
 		return;
 	}
 
 	/* Object isn't an AMDGPU object so ignore */
 	if (!amdgpu_bo_is_amdgpu_bo(bo)) {
 		placement->placement = &placements;
-		placement->busy_placement = &placements;
 		placement->num_placement = 1;
-		placement->num_busy_placement = 1;
 		return;
 	}
 
 	abo = ttm_to_amdgpu_bo(bo);
 	if (abo->flags & AMDGPU_GEM_CREATE_DISCARDABLE) {
 		placement->num_placement = 0;
-		placement->num_busy_placement = 0;
 		return;
 	}
 
@@ -128,13 +124,13 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
 	case AMDGPU_PL_OA:
 	case AMDGPU_PL_DOORBELL:
 		placement->num_placement = 0;
-		placement->num_busy_placement = 0;
 		return;
 
 	case TTM_PL_VRAM:
 		if (!adev->mman.buffer_funcs_enabled) {
 			/* Move to system memory */
 			amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_CPU);
+
 		} else if (!amdgpu_gmc_vram_full_visible(&adev->gmc) &&
 			   !(abo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) &&
 			   amdgpu_bo_in_cpu_visible_vram(abo)) {
@@ -149,8 +145,7 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
 							AMDGPU_GEM_DOMAIN_CPU);
 			abo->placements[0].fpfn = adev->gmc.visible_vram_size >> PAGE_SHIFT;
 			abo->placements[0].lpfn = 0;
-			abo->placement.busy_placement = &abo->placements[1];
-			abo->placement.num_busy_placement = 1;
+			abo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
 		} else {
 			/* Move to GTT memory */
 			amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT |
@@ -966,8 +961,6 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
 	/* allocate GART space */
 	placement.num_placement = 1;
 	placement.placement = &placements;
-	placement.num_busy_placement = 1;
-	placement.busy_placement = &placements;
 	placements.fpfn = 0;
 	placements.lpfn = adev->gmc.gart_size >> PAGE_SHIFT;
 	placements.mem_type = TTM_PL_TT;
drivers/gpu/drm/drm_gem_vram_helper.c +0 -2
index b67eafa55715..75f2eaf0d5b6 100644
@@ -147,7 +147,6 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
 		invariant_flags = TTM_PL_FLAG_TOPDOWN;
 
 	gbo->placement.placement = gbo->placements;
-	gbo->placement.busy_placement = gbo->placements;
 
 	if (pl_flag & DRM_GEM_VRAM_PL_FLAG_VRAM) {
 		gbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -160,7 +159,6 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
 	}
 
 	gbo->placement.num_placement = c;
-	gbo->placement.num_busy_placement = c;
 
 	for (i = 0; i < c; ++i) {
 		gbo->placements[i].fpfn = 0;
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +15 -22
index 6b69ef0cdbb4..80c6cafc8887 100644
@@ -65,8 +65,6 @@ static const struct ttm_place sys_placement_flags = {
 static struct ttm_placement i915_sys_placement = {
 	.num_placement = 1,
 	.placement = &sys_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags,
 };
 
 /**
@@ -157,32 +155,28 @@ i915_ttm_place_from_region(const struct intel_memory_region *mr,
 
 static void
 i915_ttm_placement_from_obj(const struct drm_i915_gem_object *obj,
-			    struct ttm_place *requested,
-			    struct ttm_place *busy,
+			    struct ttm_place *places,
 			    struct ttm_placement *placement)
 {
 	unsigned int num_allowed = obj->mm.n_placements;
 	unsigned int flags = obj->flags;
 	unsigned int i;
 
-	placement->num_placement = 1;
+	places[0].flags |= TTM_PL_FLAG_DESIRED;
 	i915_ttm_place_from_region(num_allowed ? obj->mm.placements[0] :
-				   obj->mm.region, requested, obj->bo_offset,
+				   obj->mm.region, &places[0], obj->bo_offset,
 				   obj->base.size, flags);
 
 	/* Cache this on object? */
-	placement->num_busy_placement = num_allowed;
-	for (i = 0; i < placement->num_busy_placement; ++i)
-		i915_ttm_place_from_region(obj->mm.placements[i], busy + i,
-					   obj->bo_offset, obj->base.size, flags);
-
-	if (num_allowed == 0) {
-		*busy = *requested;
-		placement->num_busy_placement = 1;
+	for (i = 0; i < num_allowed; ++i) {
+		i915_ttm_place_from_region(obj->mm.placements[i],
+					   &places[i + 1], obj->bo_offset,
+					   obj->base.size, flags);
+		places[i + 1].flags |= TTM_PL_FLAG_FALLBACK;
 	}
 
-	placement->placement = requested;
-	placement->busy_placement = busy;
+	placement->num_placement = num_allowed + 1;
+	placement->placement = places;
 }
 
 static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev,
@@ -789,7 +783,8 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
 	int ret;
 
 	/* First try only the requested placement. No eviction. */
-	real_num_busy = fetch_and_zero(&placement->num_busy_placement);
+	real_num_busy = placement->num_placement;
+	placement->num_placement = 1;
 	ret = ttm_bo_validate(bo, placement, &ctx);
 	if (ret) {
 		ret = i915_ttm_err_to_gem(ret);
@@ -805,7 +800,7 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
 		 * If the initial attempt fails, allow all accepted placements,
 		 * evicting if necessary.
 		 */
-		placement->num_busy_placement = real_num_busy;
+		placement->num_placement = real_num_busy;
 		ret = ttm_bo_validate(bo, placement, &ctx);
 		if (ret)
 			return i915_ttm_err_to_gem(ret);
@@ -839,7 +834,7 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
 
 static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
 {
-	struct ttm_place requested, busy[I915_TTM_MAX_PLACEMENTS];
+	struct ttm_place places[I915_TTM_MAX_PLACEMENTS + 1];
 	struct ttm_placement placement;
 
 	/* restricted by sg_alloc_table */
@@ -849,7 +844,7 @@ static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
 	GEM_BUG_ON(obj->mm.n_placements > I915_TTM_MAX_PLACEMENTS);
 
 	/* Move to the requested placement. */
-	i915_ttm_placement_from_obj(obj, &requested, busy, &placement);
+	i915_ttm_placement_from_obj(obj, places, &placement);
 
 	return __i915_ttm_get_pages(obj, &placement);
 }
@@ -879,9 +874,7 @@ static int __i915_ttm_migrate(struct drm_i915_gem_object *obj,
 	i915_ttm_place_from_region(mr, &requested, obj->bo_offset,
 				   obj->base.size, flags);
 	placement.num_placement = 1;
-	placement.num_busy_placement = 1;
 	placement.placement = &requested;
-	placement.busy_placement = &requested;
 
 	ret = __i915_ttm_get_pages(obj, &placement);
 	if (ret)
drivers/gpu/drm/loongson/lsdc_ttm.c +0 -2
index bf79dc55afa4..465f622ac05d 100644
@@ -54,7 +54,6 @@ static void lsdc_bo_set_placement(struct lsdc_bo *lbo, u32 domain)
 		pflags |= TTM_PL_FLAG_TOPDOWN;
 
 	lbo->placement.placement = lbo->placements;
-	lbo->placement.busy_placement = lbo->placements;
 
 	if (domain & LSDC_GEM_DOMAIN_VRAM) {
 		lbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -77,7 +76,6 @@ static void lsdc_bo_set_placement(struct lsdc_bo *lbo, u32 domain)
 	}
 
 	lbo->placement.num_placement = c;
-	lbo->placement.num_busy_placement = c;
 
 	for (i = 0; i < c; ++i) {
 		lbo->placements[i].fpfn = 0;
drivers/gpu/drm/nouveau/nouveau_bo.c +23 -36

86 lines not on this page · raw message

drivers/gpu/drm/nouveau/nouveau_bo.h +0 -1
index 70c551921a9e..e9dfab6a8156 100644
@@ -15,7 +15,6 @@ struct nouveau_bo {
 	struct ttm_placement placement;
 	u32 valid_domains;
 	struct ttm_place placements[3];
-	struct ttm_place busy_placements[3];
 	bool force_coherent;
 	struct ttm_bo_kmap_obj kmap;
 	struct list_head head;
drivers/gpu/drm/qxl/qxl_object.c +0 -2
index 06a58dad5f5c..1e46b0a6e478 100644
@@ -66,7 +66,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain)
 		pflag |= TTM_PL_FLAG_TOPDOWN;
 
 	qbo->placement.placement = qbo->placements;
-	qbo->placement.busy_placement = qbo->placements;
 	if (domain == QXL_GEM_DOMAIN_VRAM) {
 		qbo->placements[c].mem_type = TTM_PL_VRAM;
 		qbo->placements[c++].flags = pflag;
@@ -86,7 +85,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain)
 		qbo->placements[c++].flags = 0;
 	}
 	qbo->placement.num_placement = c;
-	qbo->placement.num_busy_placement = c;
 	for (i = 0; i < c; ++i) {
 		qbo->placements[i].fpfn = 0;
 		qbo->placements[i].lpfn = 0;
drivers/gpu/drm/qxl/qxl_ttm.c +0 -2
index 1a82629bce3f..765a144cea14 100644
@@ -60,9 +60,7 @@ static void qxl_evict_flags(struct ttm_buffer_object *bo,
 
 	if (!qxl_ttm_bo_is_qxl_bo(bo)) {
 		placement->placement = &placements;
-		placement->busy_placement = &placements;
 		placement->num_placement = 1;
-		placement->num_busy_placement = 1;
 		return;
 	}
 	qbo = to_qxl_bo(bo);
drivers/gpu/drm/radeon/radeon_object.c +0 -2
index 10c0fbd9d2b4..a955f8a2f7fe 100644
@@ -78,7 +78,6 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
 	u32 c = 0, i;
 
 	rbo->placement.placement = rbo->placements;
-	rbo->placement.busy_placement = rbo->placements;
 	if (domain & RADEON_GEM_DOMAIN_VRAM) {
 		/* Try placing BOs which don't need CPU access outside of the
 		 * CPU accessible part of VRAM
@@ -114,7 +113,6 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
 	}
 
 	rbo->placement.num_placement = c;
-	rbo->placement.num_busy_placement = c;
 
 	for (i = 0; i < c; ++i) {
 		if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&
drivers/gpu/drm/radeon/radeon_ttm.c +1 -7
index de4e6d78f1e1..2078b0000e22 100644
@@ -92,9 +92,7 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo,
 
 	if (!radeon_ttm_bo_is_radeon_bo(bo)) {
 		placement->placement = &placements;
-		placement->busy_placement = &placements;
 		placement->num_placement = 1;
-		placement->num_busy_placement = 1;
 		return;
 	}
 	rbo = container_of(bo, struct radeon_bo, tbo);
@@ -114,15 +112,11 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo,
 			 */
 			radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_VRAM |
 							 RADEON_GEM_DOMAIN_GTT);
-			rbo->placement.num_busy_placement = 0;
 			for (i = 0; i < rbo->placement.num_placement; i++) {
 				if (rbo->placements[i].mem_type == TTM_PL_VRAM) {
 					if (rbo->placements[i].fpfn < fpfn)
 						rbo->placements[i].fpfn = fpfn;
-				} else {
-					rbo->placement.busy_placement =
-						&rbo->placements[i];
-					rbo->placement.num_busy_placement = 1;
+					rbo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
 				}
 			}
 		} else
drivers/gpu/drm/radeon/radeon_uvd.c +0 -1
index a2cda184b2b2..058a1c8451b2 100644
@@ -324,7 +324,6 @@ void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo,
 	rbo->placements[1].fpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
 	rbo->placements[1].lpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
 	rbo->placement.num_placement++;
-	rbo->placement.num_busy_placement++;
 }
 
 void radeon_uvd_free_handles(struct radeon_device *rdev, struct drm_file *filp)
drivers/gpu/drm/ttm/ttm_bo.c +13 -8
index 8c1eaa74fa21..a5e11a92e0b9 100644
@@ -410,8 +410,8 @@ static int ttm_bo_bounce_temp_buffer(struct ttm_buffer_object *bo,
 	struct ttm_resource *hop_mem;
 	int ret;
 
-	hop_placement.num_placement = hop_placement.num_busy_placement = 1;
-	hop_placement.placement = hop_placement.busy_placement = hop;
+	hop_placement.num_placement = 1;
+	hop_placement.placement = hop;
 
 	/* find space in the bounce domain */
 	ret = ttm_bo_mem_space(bo, &hop_placement, &hop_mem, ctx);
@@ -440,10 +440,9 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
 	dma_resv_assert_held(bo->base.resv);
 
 	placement.num_placement = 0;
-	placement.num_busy_placement = 0;
 	bdev->funcs->evict_flags(bo, &placement);
 
-	if (!placement.num_placement && !placement.num_busy_placement) {
+	if (!placement.num_placement) {
 		ret = ttm_bo_wait_ctx(bo, ctx);
 		if (ret)
 			return ret;
@@ -791,6 +790,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 		const struct ttm_place *place = &placement->placement[i];
 		struct ttm_resource_manager *man;
 
+		if (place->flags & TTM_PL_FLAG_FALLBACK)
+			continue;
+
 		man = ttm_manager_type(bdev, place->mem_type);
 		if (!man || !ttm_resource_manager_used(man))
 			continue;
@@ -813,10 +815,13 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 		return 0;
 	}
 
-	for (i = 0; i < placement->num_busy_placement; ++i) {
-		const struct ttm_place *place = &placement->busy_placement[i];
+	for (i = 0; i < placement->num_placement; ++i) {
+		const struct ttm_place *place = &placement->placement[i];
 		struct ttm_resource_manager *man;
 
+		if (place->flags & TTM_PL_FLAG_DESIRED)
+			continue;
+
 		man = ttm_manager_type(bdev, place->mem_type);
 		if (!man || !ttm_resource_manager_used(man))
 			continue;
@@ -904,11 +909,11 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
 	/*
 	 * Remove the backing store if no placement is given.
 	 */
-	if (!placement->num_placement && !placement->num_busy_placement)
+	if (!placement->num_placement)
 		return ttm_bo_pipeline_gutting(bo);
 
 	/* Check whether we need to move buffer. */
-	if (bo->resource && ttm_resource_compat(bo->resource, placement))
+	if (bo->resource && ttm_resource_compatible(bo->resource, placement))
 		return 0;
 
 	/* Moving of pinned BOs is forbidden */
drivers/gpu/drm/ttm/ttm_resource.c +16 -57

97 lines not on this page · raw message

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +24 -9
index 2bfac3aad7b7..bfd41ce3c8f4 100644
@@ -742,9 +742,21 @@ void vmw_bo_move_notify(struct ttm_buffer_object *bo,
 		vmw_resource_unbind_list(vbo);
 }
 
+static u32 placement_flags(u32 domain, u32 desired, u32 fallback)
+{
+	if (desired & fallback & domain)
+		return 0;
+
+	if (desired & domain)
+		return TTM_PL_FLAG_DESIRED;
+
+	return TTM_PL_FLAG_FALLBACK;
+}
+
 static u32
-set_placement_list(struct ttm_place *pl, u32 domain)
+set_placement_list(struct ttm_place *pl, u32 desired, u32 fallback)
 {
+	u32 domain = desired | fallback;
 	u32 n = 0;
 
 	/*
@@ -752,35 +764,40 @@ set_placement_list(struct ttm_place *pl, u32 domain)
 	 */
 	if (domain & VMW_BO_DOMAIN_MOB) {
 		pl[n].mem_type = VMW_PL_MOB;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_MOB, desired,
+					      fallback);
 		pl[n].fpfn = 0;
 		pl[n].lpfn = 0;
 		n++;
 	}
 	if (domain & VMW_BO_DOMAIN_GMR) {
 		pl[n].mem_type = VMW_PL_GMR;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_GMR, desired,
+					      fallback);
 		pl[n].fpfn = 0;
 		pl[n].lpfn = 0;
 		n++;
 	}
 	if (domain & VMW_BO_DOMAIN_VRAM) {
 		pl[n].mem_type = TTM_PL_VRAM;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_VRAM, desired,
+					      fallback);
 		pl[n].fpfn = 0;
 		pl[n].lpfn = 0;
 		n++;
 	}
 	if (domain & VMW_BO_DOMAIN_WAITABLE_SYS) {
 		pl[n].mem_type = VMW_PL_SYSTEM;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_WAITABLE_SYS,
+					      desired, fallback);
 		pl[n].fpfn = 0;
 		pl[n].lpfn = 0;
 		n++;
 	}
 	if (domain & VMW_BO_DOMAIN_SYS) {
 		pl[n].mem_type = TTM_PL_SYSTEM;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_SYS, desired,
+					      fallback);
 		pl[n].fpfn = 0;
 		pl[n].lpfn = 0;
 		n++;
@@ -806,7 +823,7 @@ void vmw_bo_placement_set(struct vmw_bo *bo, u32 domain, u32 busy_domain)
 	u32 i;
 
 	pl->placement = bo->places;
-	pl->num_placement = set_placement_list(bo->places, domain);
+	pl->num_placement = set_placement_list(bo->places, domain, busy_domain);
 
 	if (drm_debug_enabled(DRM_UT_DRIVER) && bo->tbo.resource) {
 		for (i = 0; i < pl->num_placement; ++i) {
@@ -821,8 +838,6 @@ void vmw_bo_placement_set(struct vmw_bo *bo, u32 domain, u32 busy_domain)
 				 __func__, bo->tbo.resource->mem_type, domain);
 	}
 
-	pl->busy_placement = bo->busy_places;
-	pl->num_busy_placement = set_placement_list(bo->busy_places, busy_domain);
 }
 
 void vmw_bo_placement_set_default_accelerated(struct vmw_bo *bo)
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +0 -4
index a84fffcef8e1..4d23d0a70bcb 100644
@@ -46,15 +46,11 @@ static const struct ttm_place sys_placement_flags = {
 struct ttm_placement vmw_vram_placement = {
 	.num_placement = 1,
 	.placement = &vram_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &vram_placement_flags
 };
 
 struct ttm_placement vmw_sys_placement = {
 	.num_placement = 1,
 	.placement = &sys_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags
 };
 
 const size_t vmw_tt_size = sizeof(struct vmw_ttm_tt);
drivers/gpu/drm/xe/xe_bo.c +15 -18
index 8e4a3b1f6b93..1e5edc7f0b85 100644
@@ -38,22 +38,26 @@ static const struct ttm_place sys_placement_flags = {
 static struct ttm_placement sys_placement = {
 	.num_placement = 1,
 	.placement = &sys_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags,
 };
 
-static const struct ttm_place tt_placement_flags = {
-	.fpfn = 0,
-	.lpfn = 0,
-	.mem_type = XE_PL_TT,
-	.flags = 0,
+static const struct ttm_place tt_placement_flags[] = {
+	{
+		.fpfn = 0,
+		.lpfn = 0,
+		.mem_type = XE_PL_TT,
+		.flags = TTM_PL_FLAG_DESIRED,
+	},
+	{
+		.fpfn = 0,
+		.lpfn = 0,
+		.mem_type = XE_PL_SYSTEM,
+		.flags = TTM_PL_FLAG_FALLBACK,
+	}
 };
 
 static struct ttm_placement tt_placement = {
-	.num_placement = 1,
-	.placement = &tt_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags,
+	.num_placement = 2,
+	.placement = tt_placement_flags,
 };
 
 bool mem_type_is_vram(u32 mem_type)
@@ -230,8 +234,6 @@ static int __xe_bo_placement_for_flags(struct xe_device *xe, struct xe_bo *bo,
 	bo->placement = (struct ttm_placement) {
 		.num_placement = c,
 		.placement = bo->placements,
-		.num_busy_placement = c,
-		.busy_placement = bo->placements,
 	};
 
 	return 0;
@@ -251,7 +253,6 @@ static void xe_evict_flags(struct ttm_buffer_object *tbo,
 		/* Don't handle scatter gather BOs */
 		if (tbo->type == ttm_bo_type_sg) {
 			placement->num_placement = 0;
-			placement->num_busy_placement = 0;
 			return;
 		}
 
@@ -1353,8 +1354,6 @@ static int __xe_bo_fixed_placement(struct xe_device *xe,
 	bo->placement = (struct ttm_placement) {
 		.num_placement = 1,
 		.placement = place,
-		.num_busy_placement = 1,
-		.busy_placement = place,
 	};
 
 	return 0;
@@ -2112,9 +2111,7 @@ int xe_bo_migrate(struct xe_bo *bo, u32 mem_type)
 
 	xe_place_from_ttm_type(mem_type, &requested);
 	placement.num_placement = 1;
-	placement.num_busy_placement = 1;
 	placement.placement = &requested;
-	placement.busy_placement = &requested;
 
 	/*
 	 * Stolen needs to be handled like below VRAM handling if we ever need
include/drm/ttm/ttm_placement.h +6 -4
index 8074d0f6cae5..b510a4812609 100644
@@ -64,6 +64,12 @@
 /* For multihop handling */
 #define TTM_PL_FLAG_TEMPORARY   (1 << 2)
 
+/* Placement is never used during eviction */
+#define TTM_PL_FLAG_DESIRED	(1 << 3)
+
+/* Placement is only used during eviction */
+#define TTM_PL_FLAG_FALLBACK	(1 << 4)
+
 /**
  * struct ttm_place
  *
@@ -86,16 +92,12 @@ struct ttm_place {
  *
  * @num_placement:	number of preferred placements
  * @placement:		preferred placements
- * @num_busy_placement:	number of preferred placements when need to evict buffer
- * @busy_placement:	preferred placements when need to evict buffer
  *
  * Structure indicating the placement you request for an object.
  */
 struct ttm_placement {
 	unsigned		num_placement;
 	const struct ttm_place	*placement;
-	unsigned		num_busy_placement;
-	const struct ttm_place	*busy_placement;
 };
 
 #endif
include/drm/ttm/ttm_resource.h +2 -6
index 78a226eba953..1afa13f0c22b 100644
@@ -365,12 +365,8 @@ bool ttm_resource_intersects(struct ttm_device *bdev,
 			     struct ttm_resource *res,
 			     const struct ttm_place *place,
 			     size_t size);
-bool ttm_resource_compatible(struct ttm_device *bdev,
-			     struct ttm_resource *res,
-			     const struct ttm_place *place,
-			     size_t size);
-bool ttm_resource_compat(struct ttm_resource *res,
-			 struct ttm_placement *placement);
+bool ttm_resource_compatible(struct ttm_resource *res,
+			     struct ttm_placement *placement);
 void ttm_resource_set_bo(struct ttm_resource *res,
 			 struct ttm_buffer_object *bo);
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 3/5
#5 lore raw

Re: [PATCH 3/5] drm/ttm: replace busy placement with flags v6

Am 12.01.24 um 13:51 schrieb Christian König:

Quoted 14 lines

From: Somalapuram Amaranath <[email protected]>

Instead of a list of separate busy placement add flags which indicate that a placement should only be used when there is room or if we need to evict.

v2: add missing TTM_PL_FLAG_IDLE for i915
v3: fix auto build test ERROR on drm-tip/drm-tip
v4: fix some typos pointed out by checkpatch
v5: cleanup some rebase problems with VMWGFX
v6: implement some missing VMWGFX functionality pointed out by Zack,
rename the flags as suggested by Michel, rebase on drm-tip and adjust XE as well

Quoted 2 lines

For the VRAM helpers:

Quoted 866 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |  6 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 11 +---
  drivers/gpu/drm/drm_gem_vram_helper.c      |  2 -
  drivers/gpu/drm/i915/gem/i915_gem_ttm.c    | 37 +++++------
  drivers/gpu/drm/loongson/lsdc_ttm.c        |  2 -
  drivers/gpu/drm/nouveau/nouveau_bo.c       | 59 +++++++----------
  drivers/gpu/drm/nouveau/nouveau_bo.h       |  1 -
  drivers/gpu/drm/qxl/qxl_object.c           |  2 -
  drivers/gpu/drm/qxl/qxl_ttm.c              |  2 -
  drivers/gpu/drm/radeon/radeon_object.c     |  2 -
  drivers/gpu/drm/radeon/radeon_ttm.c        |  8 +--
  drivers/gpu/drm/radeon/radeon_uvd.c        |  1 -
  drivers/gpu/drm/ttm/ttm_bo.c               | 21 ++++---
  drivers/gpu/drm/ttm/ttm_resource.c         | 73 +++++-----------------
  drivers/gpu/drm/vmwgfx/vmwgfx_bo.c         | 33 +++++++---
  drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c |  4 --
  drivers/gpu/drm/xe/xe_bo.c                 | 33 +++++-----
  include/drm/ttm/ttm_placement.h            | 10 +--
  include/drm/ttm/ttm_resource.h             |  8 +--
  19 files changed, 118 insertions(+), 197 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -5
index 425cebcc5cbf..b671b0665492 100644
@@ -220,9 +220,6 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain)
 
  	placement->num_placement = c;
  	placement->placement = places;
-
-	placement->num_busy_placement = c;
-	placement->busy_placement = places;
  }
 
  /**
@@ -1397,8 +1394,7 @@ vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
  					AMDGPU_GEM_DOMAIN_GTT);
 
  	/* Avoid costly evictions; only set GTT as a busy placement */
-	abo->placement.num_busy_placement = 1;
-	abo->placement.busy_placement = &abo->placements[1];
+	abo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
 
  	r = ttm_bo_validate(bo, &abo->placement, &ctx);
  	if (unlikely(r == -EBUSY || r == -ERESTARTSYS))
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -9
index 75c9fd2c6c2a..8722beba494e 100644
@@ -102,23 +102,19 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
  	/* Don't handle scatter gather BOs */
  	if (bo->type == ttm_bo_type_sg) {
  		placement->num_placement = 0;
-		placement->num_busy_placement = 0;
  		return;
  	}
 
  	/* Object isn't an AMDGPU object so ignore */
  	if (!amdgpu_bo_is_amdgpu_bo(bo)) {
  		placement->placement = &placements;
-		placement->busy_placement = &placements;
  		placement->num_placement = 1;
-		placement->num_busy_placement = 1;
  		return;
  	}
 
  	abo = ttm_to_amdgpu_bo(bo);
  	if (abo->flags & AMDGPU_GEM_CREATE_DISCARDABLE) {
  		placement->num_placement = 0;
-		placement->num_busy_placement = 0;
  		return;
  	}
 
@@ -128,13 +124,13 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
  	case AMDGPU_PL_OA:
  	case AMDGPU_PL_DOORBELL:
  		placement->num_placement = 0;
-		placement->num_busy_placement = 0;
  		return;
 
  	case TTM_PL_VRAM:
  		if (!adev->mman.buffer_funcs_enabled) {
  			/* Move to system memory */
  			amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_CPU);
+
  		} else if (!amdgpu_gmc_vram_full_visible(&adev->gmc) &&
  			   !(abo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) &&
  			   amdgpu_bo_in_cpu_visible_vram(abo)) {
@@ -149,8 +145,7 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
  							AMDGPU_GEM_DOMAIN_CPU);
  			abo->placements[0].fpfn = adev->gmc.visible_vram_size >> PAGE_SHIFT;
  			abo->placements[0].lpfn = 0;
-			abo->placement.busy_placement = &abo->placements[1];
-			abo->placement.num_busy_placement = 1;
+			abo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
  		} else {
  			/* Move to GTT memory */
  			amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT |
@@ -966,8 +961,6 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
  	/* allocate GART space */
  	placement.num_placement = 1;
  	placement.placement = &placements;
-	placement.num_busy_placement = 1;
-	placement.busy_placement = &placements;
  	placements.fpfn = 0;
  	placements.lpfn = adev->gmc.gart_size >> PAGE_SHIFT;
  	placements.mem_type = TTM_PL_TT;
drivers/gpu/drm/drm_gem_vram_helper.c +0 -2
index b67eafa55715..75f2eaf0d5b6 100644
@@ -147,7 +147,6 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
  		invariant_flags = TTM_PL_FLAG_TOPDOWN;
 
  	gbo->placement.placement = gbo->placements;
-	gbo->placement.busy_placement = gbo->placements;
 
  	if (pl_flag & DRM_GEM_VRAM_PL_FLAG_VRAM) {
  		gbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -160,7 +159,6 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
  	}
 
  	gbo->placement.num_placement = c;
-	gbo->placement.num_busy_placement = c;
 
  	for (i = 0; i < c; ++i) {
  		gbo->placements[i].fpfn = 0;
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +15 -22
index 6b69ef0cdbb4..80c6cafc8887 100644
@@ -65,8 +65,6 @@ static const struct ttm_place sys_placement_flags = {
  static struct ttm_placement i915_sys_placement = {
  	.num_placement = 1,
  	.placement = &sys_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags,
  };
 
  /**
@@ -157,32 +155,28 @@ i915_ttm_place_from_region(const struct intel_memory_region *mr,
 
  static void
  i915_ttm_placement_from_obj(const struct drm_i915_gem_object *obj,
-			    struct ttm_place *requested,
-			    struct ttm_place *busy,
+			    struct ttm_place *places,
  			    struct ttm_placement *placement)
  {
  	unsigned int num_allowed = obj->mm.n_placements;
  	unsigned int flags = obj->flags;
  	unsigned int i;
 
-	placement->num_placement = 1;
+	places[0].flags |= TTM_PL_FLAG_DESIRED;
  	i915_ttm_place_from_region(num_allowed ? obj->mm.placements[0] :
-				   obj->mm.region, requested, obj->bo_offset,
+				   obj->mm.region, &places[0], obj->bo_offset,
  				   obj->base.size, flags);
 
  	/* Cache this on object? */
-	placement->num_busy_placement = num_allowed;
-	for (i = 0; i < placement->num_busy_placement; ++i)
-		i915_ttm_place_from_region(obj->mm.placements[i], busy + i,
-					   obj->bo_offset, obj->base.size, flags);
-
-	if (num_allowed == 0) {
-		*busy = *requested;
-		placement->num_busy_placement = 1;
+	for (i = 0; i < num_allowed; ++i) {
+		i915_ttm_place_from_region(obj->mm.placements[i],
+					   &places[i + 1], obj->bo_offset,
+					   obj->base.size, flags);
+		places[i + 1].flags |= TTM_PL_FLAG_FALLBACK;
  	}
 
-	placement->placement = requested;
-	placement->busy_placement = busy;
+	placement->num_placement = num_allowed + 1;
+	placement->placement = places;
  }
 
  static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev,
@@ -789,7 +783,8 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
  	int ret;
 
  	/* First try only the requested placement. No eviction. */
-	real_num_busy = fetch_and_zero(&placement->num_busy_placement);
+	real_num_busy = placement->num_placement;
+	placement->num_placement = 1;
  	ret = ttm_bo_validate(bo, placement, &ctx);
  	if (ret) {
  		ret = i915_ttm_err_to_gem(ret);
@@ -805,7 +800,7 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
  		 * If the initial attempt fails, allow all accepted placements,
  		 * evicting if necessary.
  		 */
-		placement->num_busy_placement = real_num_busy;
+		placement->num_placement = real_num_busy;
  		ret = ttm_bo_validate(bo, placement, &ctx);
  		if (ret)
  			return i915_ttm_err_to_gem(ret);
@@ -839,7 +834,7 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
 
  static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
  {
-	struct ttm_place requested, busy[I915_TTM_MAX_PLACEMENTS];
+	struct ttm_place places[I915_TTM_MAX_PLACEMENTS + 1];
  	struct ttm_placement placement;
 
  	/* restricted by sg_alloc_table */
@@ -849,7 +844,7 @@ static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
  	GEM_BUG_ON(obj->mm.n_placements > I915_TTM_MAX_PLACEMENTS);
 
  	/* Move to the requested placement. */
-	i915_ttm_placement_from_obj(obj, &requested, busy, &placement);
+	i915_ttm_placement_from_obj(obj, places, &placement);
 
  	return __i915_ttm_get_pages(obj, &placement);
  }
@@ -879,9 +874,7 @@ static int __i915_ttm_migrate(struct drm_i915_gem_object *obj,
  	i915_ttm_place_from_region(mr, &requested, obj->bo_offset,
  				   obj->base.size, flags);
  	placement.num_placement = 1;
-	placement.num_busy_placement = 1;
  	placement.placement = &requested;
-	placement.busy_placement = &requested;
 
  	ret = __i915_ttm_get_pages(obj, &placement);
  	if (ret)
drivers/gpu/drm/loongson/lsdc_ttm.c +0 -2
index bf79dc55afa4..465f622ac05d 100644
@@ -54,7 +54,6 @@ static void lsdc_bo_set_placement(struct lsdc_bo *lbo, u32 domain)
  		pflags |= TTM_PL_FLAG_TOPDOWN;
 
  	lbo->placement.placement = lbo->placements;
-	lbo->placement.busy_placement = lbo->placements;
 
  	if (domain & LSDC_GEM_DOMAIN_VRAM) {
  		lbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -77,7 +76,6 @@ static void lsdc_bo_set_placement(struct lsdc_bo *lbo, u32 domain)
  	}
 
  	lbo->placement.num_placement = c;
-	lbo->placement.num_busy_placement = c;
 
  	for (i = 0; i < c; ++i) {
  		lbo->placements[i].fpfn = 0;
drivers/gpu/drm/nouveau/nouveau_bo.c +23 -36
index 00cc7d1abaa3..56dcd25db1ce 100644
@@ -404,27 +404,6 @@ nouveau_bo_new(struct nouveau_cli *cli, u64 size, int align,
  	return 0;
  }
 
-static void
-set_placement_list(struct ttm_place *pl, unsigned *n, uint32_t domain)
-{
-	*n = 0;
-
-	if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
-		pl[*n].mem_type = TTM_PL_VRAM;
-		pl[*n].flags = 0;
-		(*n)++;
-	}
-	if (domain & NOUVEAU_GEM_DOMAIN_GART) {
-		pl[*n].mem_type = TTM_PL_TT;
-		pl[*n].flags = 0;
-		(*n)++;
-	}
-	if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
-		pl[*n].mem_type = TTM_PL_SYSTEM;
-		pl[(*n)++].flags = 0;
-	}
-}
-
  static void
  set_placement_range(struct nouveau_bo *nvbo, uint32_t domain)
  {
@@ -452,10 +431,6 @@ set_placement_range(struct nouveau_bo *nvbo, uint32_t domain)
  			nvbo->placements[i].fpfn = fpfn;
  			nvbo->placements[i].lpfn = lpfn;
  		}
-		for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-			nvbo->busy_placements[i].fpfn = fpfn;
-			nvbo->busy_placements[i].lpfn = lpfn;
-		}
  	}
  }
 
@@ -463,15 +438,32 @@ void
  nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t domain,
  			 uint32_t busy)
  {
-	struct ttm_placement *pl = &nvbo->placement;
+	unsigned int *n = &nvbo->placement.num_placement;
+	struct ttm_place *pl = nvbo->placements;
 
-	pl->placement = nvbo->placements;
-	set_placement_list(nvbo->placements, &pl->num_placement, domain);
+	domain |= busy;
 
-	pl->busy_placement = nvbo->busy_placements;
-	set_placement_list(nvbo->busy_placements, &pl->num_busy_placement,
-			   domain | busy);
+	*n = 0;
+	if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
+		pl[*n].mem_type = TTM_PL_VRAM;
+		pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_VRAM ?
+			TTM_PL_FLAG_FALLBACK : 0;
+		(*n)++;
+	}
+	if (domain & NOUVEAU_GEM_DOMAIN_GART) {
+		pl[*n].mem_type = TTM_PL_TT;
+		pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_GART ?
+			TTM_PL_FLAG_FALLBACK : 0;
+		(*n)++;
+	}
+	if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
+		pl[*n].mem_type = TTM_PL_SYSTEM;
+		pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_CPU ?
+			TTM_PL_FLAG_FALLBACK : 0;
+		(*n)++;
+	}
 
+	nvbo->placement.placement = nvbo->placements;
  	set_placement_range(nvbo, domain);
  }
 
@@ -1314,11 +1306,6 @@ vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
  			nvbo->placements[i].lpfn = mappable;
  		}
 
-		for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-			nvbo->busy_placements[i].fpfn = 0;
-			nvbo->busy_placements[i].lpfn = mappable;
-		}
-
  		nouveau_bo_placement_set(nvbo, NOUVEAU_GEM_DOMAIN_VRAM, 0);
  	}
 
drivers/gpu/drm/nouveau/nouveau_bo.h +0 -1
index 70c551921a9e..e9dfab6a8156 100644
@@ -15,7 +15,6 @@ struct nouveau_bo {
  	struct ttm_placement placement;
  	u32 valid_domains;
  	struct ttm_place placements[3];
-	struct ttm_place busy_placements[3];
  	bool force_coherent;
  	struct ttm_bo_kmap_obj kmap;
  	struct list_head head;
drivers/gpu/drm/qxl/qxl_object.c +0 -2
index 06a58dad5f5c..1e46b0a6e478 100644
@@ -66,7 +66,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain)
  		pflag |= TTM_PL_FLAG_TOPDOWN;
 
  	qbo->placement.placement = qbo->placements;
-	qbo->placement.busy_placement = qbo->placements;
  	if (domain == QXL_GEM_DOMAIN_VRAM) {
  		qbo->placements[c].mem_type = TTM_PL_VRAM;
  		qbo->placements[c++].flags = pflag;
@@ -86,7 +85,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain)
  		qbo->placements[c++].flags = 0;
  	}
  	qbo->placement.num_placement = c;
-	qbo->placement.num_busy_placement = c;
  	for (i = 0; i < c; ++i) {
  		qbo->placements[i].fpfn = 0;
  		qbo->placements[i].lpfn = 0;
drivers/gpu/drm/qxl/qxl_ttm.c +0 -2
index 1a82629bce3f..765a144cea14 100644
@@ -60,9 +60,7 @@ static void qxl_evict_flags(struct ttm_buffer_object *bo,
 
  	if (!qxl_ttm_bo_is_qxl_bo(bo)) {
  		placement->placement = &placements;
-		placement->busy_placement = &placements;
  		placement->num_placement = 1;
-		placement->num_busy_placement = 1;
  		return;
  	}
  	qbo = to_qxl_bo(bo);
drivers/gpu/drm/radeon/radeon_object.c +0 -2
index 10c0fbd9d2b4..a955f8a2f7fe 100644
@@ -78,7 +78,6 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
  	u32 c = 0, i;
 
  	rbo->placement.placement = rbo->placements;
-	rbo->placement.busy_placement = rbo->placements;
  	if (domain & RADEON_GEM_DOMAIN_VRAM) {
  		/* Try placing BOs which don't need CPU access outside of the
  		 * CPU accessible part of VRAM
@@ -114,7 +113,6 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
  	}
 
  	rbo->placement.num_placement = c;
-	rbo->placement.num_busy_placement = c;
 
  	for (i = 0; i < c; ++i) {
  		if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&
drivers/gpu/drm/radeon/radeon_ttm.c +1 -7
index de4e6d78f1e1..2078b0000e22 100644
@@ -92,9 +92,7 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo,
 
  	if (!radeon_ttm_bo_is_radeon_bo(bo)) {
  		placement->placement = &placements;
-		placement->busy_placement = &placements;
  		placement->num_placement = 1;
-		placement->num_busy_placement = 1;
  		return;
  	}
  	rbo = container_of(bo, struct radeon_bo, tbo);
@@ -114,15 +112,11 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo,
  			 */
  			radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_VRAM |
  							 RADEON_GEM_DOMAIN_GTT);
-			rbo->placement.num_busy_placement = 0;
  			for (i = 0; i < rbo->placement.num_placement; i++) {
  				if (rbo->placements[i].mem_type == TTM_PL_VRAM) {
  					if (rbo->placements[i].fpfn < fpfn)
  						rbo->placements[i].fpfn = fpfn;
-				} else {
-					rbo->placement.busy_placement =
-						&rbo->placements[i];
-					rbo->placement.num_busy_placement = 1;
+					rbo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
  				}
  			}
  		} else
drivers/gpu/drm/radeon/radeon_uvd.c +0 -1
index a2cda184b2b2..058a1c8451b2 100644
@@ -324,7 +324,6 @@ void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo,
  	rbo->placements[1].fpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
  	rbo->placements[1].lpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
  	rbo->placement.num_placement++;
-	rbo->placement.num_busy_placement++;
  }
 
  void radeon_uvd_free_handles(struct radeon_device *rdev, struct drm_file *filp)
drivers/gpu/drm/ttm/ttm_bo.c +13 -8
index 8c1eaa74fa21..a5e11a92e0b9 100644
@@ -410,8 +410,8 @@ static int ttm_bo_bounce_temp_buffer(struct ttm_buffer_object *bo,
  	struct ttm_resource *hop_mem;
  	int ret;
 
-	hop_placement.num_placement = hop_placement.num_busy_placement = 1;
-	hop_placement.placement = hop_placement.busy_placement = hop;
+	hop_placement.num_placement = 1;
+	hop_placement.placement = hop;
 
  	/* find space in the bounce domain */
  	ret = ttm_bo_mem_space(bo, &hop_placement, &hop_mem, ctx);
@@ -440,10 +440,9 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
  	dma_resv_assert_held(bo->base.resv);
 
  	placement.num_placement = 0;
-	placement.num_busy_placement = 0;
  	bdev->funcs->evict_flags(bo, &placement);
 
-	if (!placement.num_placement && !placement.num_busy_placement) {
+	if (!placement.num_placement) {
  		ret = ttm_bo_wait_ctx(bo, ctx);
  		if (ret)
  			return ret;
@@ -791,6 +790,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
  		const struct ttm_place *place = &placement->placement[i];
  		struct ttm_resource_manager *man;
 
+		if (place->flags & TTM_PL_FLAG_FALLBACK)
+			continue;
+
  		man = ttm_manager_type(bdev, place->mem_type);
  		if (!man || !ttm_resource_manager_used(man))
  			continue;
@@ -813,10 +815,13 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
  		return 0;
  	}
 
-	for (i = 0; i < placement->num_busy_placement; ++i) {
-		const struct ttm_place *place = &placement->busy_placement[i];
+	for (i = 0; i < placement->num_placement; ++i) {
+		const struct ttm_place *place = &placement->placement[i];
  		struct ttm_resource_manager *man;
 
+		if (place->flags & TTM_PL_FLAG_DESIRED)
+			continue;
+
  		man = ttm_manager_type(bdev, place->mem_type);
  		if (!man || !ttm_resource_manager_used(man))
  			continue;
@@ -904,11 +909,11 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
  	/*
  	 * Remove the backing store if no placement is given.
  	 */
-	if (!placement->num_placement && !placement->num_busy_placement)
+	if (!placement->num_placement)
  		return ttm_bo_pipeline_gutting(bo);
 
  	/* Check whether we need to move buffer. */
-	if (bo->resource && ttm_resource_compat(bo->resource, placement))
+	if (bo->resource && ttm_resource_compatible(bo->resource, placement))
  		return 0;
 
  	/* Moving of pinned BOs is forbidden */
drivers/gpu/drm/ttm/ttm_resource.c +16 -57
index 02b96d23fdb9..fb14f7716cf8 100644
@@ -291,37 +291,15 @@ bool ttm_resource_intersects(struct ttm_device *bdev,
  }
 
  /**
- * ttm_resource_compatible - test for compatibility
+ * ttm_resource_compatible - check if resource is compatible with placement
   *
- * @bdev: TTM device structure
- * @res: The resource to test
- * @place: The placement to test
- * @size: How many bytes the new allocation needs.
- *
- * Test if @res compatible with @place and @size.
+ * @res: the resource to check
+ * @placement: the placement to check against
   *
- * Returns true if the res placement compatible with @place and @size.
+ * Returns true if the placement is compatible.
   */
-bool ttm_resource_compatible(struct ttm_device *bdev,
-			     struct ttm_resource *res,
-			     const struct ttm_place *place,
-			     size_t size)
-{
-	struct ttm_resource_manager *man;
-
-	if (!res || !place)
-		return false;
-
-	man = ttm_manager_type(bdev, res->mem_type);
-	if (!man->func->compatible)
-		return true;
-
-	return man->func->compatible(man, res, place, size);
-}
-
-static bool ttm_resource_places_compat(struct ttm_resource *res,
-				       const struct ttm_place *places,
-				       unsigned num_placement)
+bool ttm_resource_compatible(struct ttm_resource *res,
+			     struct ttm_placement *placement)
  {
  	struct ttm_buffer_object *bo = res->bo;
  	struct ttm_device *bdev = bo->bdev;
@@ -330,44 +308,25 @@ static bool ttm_resource_places_compat(struct ttm_resource *res,
  	if (res->placement & TTM_PL_FLAG_TEMPORARY)
  		return false;
 
-	for (i = 0; i < num_placement; i++) {
-		const struct ttm_place *heap = &places[i];
+	for (i = 0; i < placement->num_placement; i++) {
+		const struct ttm_place *place = &placement->placement[i];
+		struct ttm_resource_manager *man;
 
-		if (!ttm_resource_compatible(bdev, res, heap, bo->base.size))
+		if (res->mem_type != place->mem_type)
+			continue;
+
+		man = ttm_manager_type(bdev, res->mem_type);
+		if (man->func->compatible &&
+		    !man->func->compatible(man, res, place, bo->base.size))
  			continue;
 
-		if ((res->mem_type == heap->mem_type) &&
-		    (!(heap->flags & TTM_PL_FLAG_CONTIGUOUS) ||
+		if ((!(place->flags & TTM_PL_FLAG_CONTIGUOUS) ||
  		     (res->placement & TTM_PL_FLAG_CONTIGUOUS)))
  			return true;
  	}
  	return false;
  }
 
-/**
- * ttm_resource_compat - check if resource is compatible with placement
- *
- * @res: the resource to check
- * @placement: the placement to check against
- *
- * Returns true if the placement is compatible.
- */
-bool ttm_resource_compat(struct ttm_resource *res,
-			 struct ttm_placement *placement)
-{
-	if (ttm_resource_places_compat(res, placement->placement,
-				       placement->num_placement))
-		return true;
-
-	if ((placement->busy_placement != placement->placement ||
-	     placement->num_busy_placement > placement->num_placement) &&
-	    ttm_resource_places_compat(res, placement->busy_placement,
-				       placement->num_busy_placement))
-		return true;
-
-	return false;
-}
-
  void ttm_resource_set_bo(struct ttm_resource *res,
  			 struct ttm_buffer_object *bo)
  {
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +24 -9
index 2bfac3aad7b7..bfd41ce3c8f4 100644
@@ -742,9 +742,21 @@ void vmw_bo_move_notify(struct ttm_buffer_object *bo,
  		vmw_resource_unbind_list(vbo);
  }
 
+static u32 placement_flags(u32 domain, u32 desired, u32 fallback)
+{
+	if (desired & fallback & domain)
+		return 0;
+
+	if (desired & domain)
+		return TTM_PL_FLAG_DESIRED;
+
+	return TTM_PL_FLAG_FALLBACK;
+}
+
  static u32
-set_placement_list(struct ttm_place *pl, u32 domain)
+set_placement_list(struct ttm_place *pl, u32 desired, u32 fallback)
  {
+	u32 domain = desired | fallback;
  	u32 n = 0;
 
  	/*
@@ -752,35 +764,40 @@ set_placement_list(struct ttm_place *pl, u32 domain)
  	 */
  	if (domain & VMW_BO_DOMAIN_MOB) {
  		pl[n].mem_type = VMW_PL_MOB;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_MOB, desired,
+					      fallback);
  		pl[n].fpfn = 0;
  		pl[n].lpfn = 0;
  		n++;
  	}
  	if (domain & VMW_BO_DOMAIN_GMR) {
  		pl[n].mem_type = VMW_PL_GMR;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_GMR, desired,
+					      fallback);
  		pl[n].fpfn = 0;
  		pl[n].lpfn = 0;
  		n++;
  	}
  	if (domain & VMW_BO_DOMAIN_VRAM) {
  		pl[n].mem_type = TTM_PL_VRAM;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_VRAM, desired,
+					      fallback);
  		pl[n].fpfn = 0;
  		pl[n].lpfn = 0;
  		n++;
  	}
  	if (domain & VMW_BO_DOMAIN_WAITABLE_SYS) {
  		pl[n].mem_type = VMW_PL_SYSTEM;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_WAITABLE_SYS,
+					      desired, fallback);
  		pl[n].fpfn = 0;
  		pl[n].lpfn = 0;
  		n++;
  	}
  	if (domain & VMW_BO_DOMAIN_SYS) {
  		pl[n].mem_type = TTM_PL_SYSTEM;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_SYS, desired,
+					      fallback);
  		pl[n].fpfn = 0;
  		pl[n].lpfn = 0;
  		n++;
@@ -806,7 +823,7 @@ void vmw_bo_placement_set(struct vmw_bo *bo, u32 domain, u32 busy_domain)
  	u32 i;
 
  	pl->placement = bo->places;
-	pl->num_placement = set_placement_list(bo->places, domain);
+	pl->num_placement = set_placement_list(bo->places, domain, busy_domain);
 
  	if (drm_debug_enabled(DRM_UT_DRIVER) && bo->tbo.resource) {
  		for (i = 0; i < pl->num_placement; ++i) {
@@ -821,8 +838,6 @@ void vmw_bo_placement_set(struct vmw_bo *bo, u32 domain, u32 busy_domain)
  				 __func__, bo->tbo.resource->mem_type, domain);
  	}
 
-	pl->busy_placement = bo->busy_places;
-	pl->num_busy_placement = set_placement_list(bo->busy_places, busy_domain);
  }
 
  void vmw_bo_placement_set_default_accelerated(struct vmw_bo *bo)
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +0 -4
index a84fffcef8e1..4d23d0a70bcb 100644
@@ -46,15 +46,11 @@ static const struct ttm_place sys_placement_flags = {
  struct ttm_placement vmw_vram_placement = {
  	.num_placement = 1,
  	.placement = &vram_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &vram_placement_flags
  };
 
  struct ttm_placement vmw_sys_placement = {
  	.num_placement = 1,
  	.placement = &sys_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags
  };
 
  const size_t vmw_tt_size = sizeof(struct vmw_ttm_tt);
drivers/gpu/drm/xe/xe_bo.c +15 -18
index 8e4a3b1f6b93..1e5edc7f0b85 100644
@@ -38,22 +38,26 @@ static const struct ttm_place sys_placement_flags = {
  static struct ttm_placement sys_placement = {
  	.num_placement = 1,
  	.placement = &sys_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags,
  };
 
-static const struct ttm_place tt_placement_flags = {
-	.fpfn = 0,
-	.lpfn = 0,
-	.mem_type = XE_PL_TT,
-	.flags = 0,
+static const struct ttm_place tt_placement_flags[] = {
+	{
+		.fpfn = 0,
+		.lpfn = 0,
+		.mem_type = XE_PL_TT,
+		.flags = TTM_PL_FLAG_DESIRED,
+	},
+	{
+		.fpfn = 0,
+		.lpfn = 0,
+		.mem_type = XE_PL_SYSTEM,
+		.flags = TTM_PL_FLAG_FALLBACK,
+	}
  };
 
  static struct ttm_placement tt_placement = {
-	.num_placement = 1,
-	.placement = &tt_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags,
+	.num_placement = 2,
+	.placement = tt_placement_flags,
  };
 
  bool mem_type_is_vram(u32 mem_type)
@@ -230,8 +234,6 @@ static int __xe_bo_placement_for_flags(struct xe_device *xe, struct xe_bo *bo,
  	bo->placement = (struct ttm_placement) {
  		.num_placement = c,
  		.placement = bo->placements,
-		.num_busy_placement = c,
-		.busy_placement = bo->placements,
  	};
 
  	return 0;
@@ -251,7 +253,6 @@ static void xe_evict_flags(struct ttm_buffer_object *tbo,
  		/* Don't handle scatter gather BOs */
  		if (tbo->type == ttm_bo_type_sg) {
  			placement->num_placement = 0;
-			placement->num_busy_placement = 0;
  			return;
  		}
 
@@ -1353,8 +1354,6 @@ static int __xe_bo_fixed_placement(struct xe_device *xe,
  	bo->placement = (struct ttm_placement) {
  		.num_placement = 1,
  		.placement = place,
-		.num_busy_placement = 1,
-		.busy_placement = place,
  	};
 
  	return 0;
@@ -2112,9 +2111,7 @@ int xe_bo_migrate(struct xe_bo *bo, u32 mem_type)
 
  	xe_place_from_ttm_type(mem_type, &requested);
  	placement.num_placement = 1;
-	placement.num_busy_placement = 1;
  	placement.placement = &requested;
-	placement.busy_placement = &requested;
 
  	/*
  	 * Stolen needs to be handled like below VRAM handling if we ever need
include/drm/ttm/ttm_placement.h +6 -4
index 8074d0f6cae5..b510a4812609 100644
@@ -64,6 +64,12 @@
  /* For multihop handling */
  #define TTM_PL_FLAG_TEMPORARY   (1 << 2)
 
+/* Placement is never used during eviction */
+#define TTM_PL_FLAG_DESIRED	(1 << 3)
+
+/* Placement is only used during eviction */
+#define TTM_PL_FLAG_FALLBACK	(1 << 4)
+
  /**
   * struct ttm_place
   *
@@ -86,16 +92,12 @@ struct ttm_place {
   *
   * @num_placement:	number of preferred placements
   * @placement:		preferred placements
- * @num_busy_placement:	number of preferred placements when need to evict buffer
- * @busy_placement:	preferred placements when need to evict buffer
   *
   * Structure indicating the placement you request for an object.
   */
  struct ttm_placement {
  	unsigned		num_placement;
  	const struct ttm_place	*placement;
-	unsigned		num_busy_placement;
-	const struct ttm_place	*busy_placement;
  };
 
  #endif
include/drm/ttm/ttm_resource.h +2 -6
index 78a226eba953..1afa13f0c22b 100644
@@ -365,12 +365,8 @@ bool ttm_resource_intersects(struct ttm_device *bdev,
  			     struct ttm_resource *res,
  			     const struct ttm_place *place,
  			     size_t size);
-bool ttm_resource_compatible(struct ttm_device *bdev,
-			     struct ttm_resource *res,
-			     const struct ttm_place *place,
-			     size_t size);
-bool ttm_resource_compat(struct ttm_resource *res,
-			 struct ttm_placement *placement);
+bool ttm_resource_compatible(struct ttm_resource *res,
+			     struct ttm_placement *placement);
  void ttm_resource_set_bo(struct ttm_resource *res,
  			 struct ttm_buffer_object *bo);
 
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#6 lore raw

Re: [PATCH 3/5] drm/ttm: replace busy placement with flags v6

In reply to Christian König

Hi, Christian

Xe changes look good. Will send the series to xe ci to check for regressions.

/Thomas

Quoted 882 lines · Christian König

From: Somalapuram Amaranath <[email protected]>

Instead of a list of separate busy placement add flags which indicate that a placement should only be used when there is room or if we need to evict.

v2: add missing TTM_PL_FLAG_IDLE for i915
v3: fix auto build test ERROR on drm-tip/drm-tip
v4: fix some typos pointed out by checkpatch
v5: cleanup some rebase problems with VMWGFX
v6: implement some missing VMWGFX functionality pointed out by Zack,
rename the flags as suggested by Michel, rebase on drm-tip and adjust XE as well

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |  6 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 11 +---
  drivers/gpu/drm/drm_gem_vram_helper.c      |  2 -
  drivers/gpu/drm/i915/gem/i915_gem_ttm.c    | 37 +++++------
  drivers/gpu/drm/loongson/lsdc_ttm.c        |  2 -
  drivers/gpu/drm/nouveau/nouveau_bo.c       | 59 +++++++----------
  drivers/gpu/drm/nouveau/nouveau_bo.h       |  1 -
  drivers/gpu/drm/qxl/qxl_object.c           |  2 -
  drivers/gpu/drm/qxl/qxl_ttm.c              |  2 -
  drivers/gpu/drm/radeon/radeon_object.c     |  2 -
  drivers/gpu/drm/radeon/radeon_ttm.c        |  8 +--
  drivers/gpu/drm/radeon/radeon_uvd.c        |  1 -
  drivers/gpu/drm/ttm/ttm_bo.c               | 21 ++++---
  drivers/gpu/drm/ttm/ttm_resource.c         | 73 +++++-----------------
  drivers/gpu/drm/vmwgfx/vmwgfx_bo.c         | 33 +++++++---
  drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c |  4 --
  drivers/gpu/drm/xe/xe_bo.c                 | 33 +++++-----
  include/drm/ttm/ttm_placement.h            | 10 +--
  include/drm/ttm/ttm_resource.h             |  8 +--
  19 files changed, 118 insertions(+), 197 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -5
index 425cebcc5cbf..b671b0665492 100644
@@ -220,9 +220,6 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain)
 
  	placement->num_placement = c;
  	placement->placement = places;
-
-	placement->num_busy_placement = c;
-	placement->busy_placement = places;
  }
 
  /**
@@ -1397,8 +1394,7 @@ vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
  					AMDGPU_GEM_DOMAIN_GTT);
 
  	/* Avoid costly evictions; only set GTT as a busy placement */
-	abo->placement.num_busy_placement = 1;
-	abo->placement.busy_placement = &abo->placements[1];
+	abo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
 
  	r = ttm_bo_validate(bo, &abo->placement, &ctx);
  	if (unlikely(r == -EBUSY || r == -ERESTARTSYS))
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -9
index 75c9fd2c6c2a..8722beba494e 100644
@@ -102,23 +102,19 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
  	/* Don't handle scatter gather BOs */
  	if (bo->type == ttm_bo_type_sg) {
  		placement->num_placement = 0;
-		placement->num_busy_placement = 0;
  		return;
  	}
 
  	/* Object isn't an AMDGPU object so ignore */
  	if (!amdgpu_bo_is_amdgpu_bo(bo)) {
  		placement->placement = &placements;
-		placement->busy_placement = &placements;
  		placement->num_placement = 1;
-		placement->num_busy_placement = 1;
  		return;
  	}
 
  	abo = ttm_to_amdgpu_bo(bo);
  	if (abo->flags & AMDGPU_GEM_CREATE_DISCARDABLE) {
  		placement->num_placement = 0;
-		placement->num_busy_placement = 0;
  		return;
  	}
 
@@ -128,13 +124,13 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
  	case AMDGPU_PL_OA:
  	case AMDGPU_PL_DOORBELL:
  		placement->num_placement = 0;
-		placement->num_busy_placement = 0;
  		return;
 
  	case TTM_PL_VRAM:
  		if (!adev->mman.buffer_funcs_enabled) {
  			/* Move to system memory */
  			amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_CPU);
+
  		} else if (!amdgpu_gmc_vram_full_visible(&adev->gmc) &&
  			   !(abo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) &&
  			   amdgpu_bo_in_cpu_visible_vram(abo)) {
@@ -149,8 +145,7 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
  							AMDGPU_GEM_DOMAIN_CPU);
  			abo->placements[0].fpfn = adev->gmc.visible_vram_size >> PAGE_SHIFT;
  			abo->placements[0].lpfn = 0;
-			abo->placement.busy_placement = &abo->placements[1];
-			abo->placement.num_busy_placement = 1;
+			abo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
  		} else {
  			/* Move to GTT memory */
  			amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT |
@@ -966,8 +961,6 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
  	/* allocate GART space */
  	placement.num_placement = 1;
  	placement.placement = &placements;
-	placement.num_busy_placement = 1;
-	placement.busy_placement = &placements;
  	placements.fpfn = 0;
  	placements.lpfn = adev->gmc.gart_size >> PAGE_SHIFT;
  	placements.mem_type = TTM_PL_TT;
drivers/gpu/drm/drm_gem_vram_helper.c +0 -2
index b67eafa55715..75f2eaf0d5b6 100644
@@ -147,7 +147,6 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
  		invariant_flags = TTM_PL_FLAG_TOPDOWN;
 
  	gbo->placement.placement = gbo->placements;
-	gbo->placement.busy_placement = gbo->placements;
 
  	if (pl_flag & DRM_GEM_VRAM_PL_FLAG_VRAM) {
  		gbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -160,7 +159,6 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
  	}
 
  	gbo->placement.num_placement = c;
-	gbo->placement.num_busy_placement = c;
 
  	for (i = 0; i < c; ++i) {
  		gbo->placements[i].fpfn = 0;
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +15 -22
index 6b69ef0cdbb4..80c6cafc8887 100644
@@ -65,8 +65,6 @@ static const struct ttm_place sys_placement_flags = {
  static struct ttm_placement i915_sys_placement = {
  	.num_placement = 1,
  	.placement = &sys_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags,
  };
 
  /**
@@ -157,32 +155,28 @@ i915_ttm_place_from_region(const struct intel_memory_region *mr,
 
  static void
  i915_ttm_placement_from_obj(const struct drm_i915_gem_object *obj,
-			    struct ttm_place *requested,
-			    struct ttm_place *busy,
+			    struct ttm_place *places,
  			    struct ttm_placement *placement)
  {
  	unsigned int num_allowed = obj->mm.n_placements;
  	unsigned int flags = obj->flags;
  	unsigned int i;
 
-	placement->num_placement = 1;
+	places[0].flags |= TTM_PL_FLAG_DESIRED;
  	i915_ttm_place_from_region(num_allowed ? obj->mm.placements[0] :
-				   obj->mm.region, requested, obj->bo_offset,
+				   obj->mm.region, &places[0], obj->bo_offset,
  				   obj->base.size, flags);
 
  	/* Cache this on object? */
-	placement->num_busy_placement = num_allowed;
-	for (i = 0; i < placement->num_busy_placement; ++i)
-		i915_ttm_place_from_region(obj->mm.placements[i], busy + i,
-					   obj->bo_offset, obj->base.size, flags);
-
-	if (num_allowed == 0) {
-		*busy = *requested;
-		placement->num_busy_placement = 1;
+	for (i = 0; i < num_allowed; ++i) {
+		i915_ttm_place_from_region(obj->mm.placements[i],
+					   &places[i + 1], obj->bo_offset,
+					   obj->base.size, flags);
+		places[i + 1].flags |= TTM_PL_FLAG_FALLBACK;
  	}
 
-	placement->placement = requested;
-	placement->busy_placement = busy;
+	placement->num_placement = num_allowed + 1;
+	placement->placement = places;
  }
 
  static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev,
@@ -789,7 +783,8 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
  	int ret;
 
  	/* First try only the requested placement. No eviction. */
-	real_num_busy = fetch_and_zero(&placement->num_busy_placement);
+	real_num_busy = placement->num_placement;
+	placement->num_placement = 1;
  	ret = ttm_bo_validate(bo, placement, &ctx);
  	if (ret) {
  		ret = i915_ttm_err_to_gem(ret);
@@ -805,7 +800,7 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
  		 * If the initial attempt fails, allow all accepted placements,
  		 * evicting if necessary.
  		 */
-		placement->num_busy_placement = real_num_busy;
+		placement->num_placement = real_num_busy;
  		ret = ttm_bo_validate(bo, placement, &ctx);
  		if (ret)
  			return i915_ttm_err_to_gem(ret);
@@ -839,7 +834,7 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
 
  static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
  {
-	struct ttm_place requested, busy[I915_TTM_MAX_PLACEMENTS];
+	struct ttm_place places[I915_TTM_MAX_PLACEMENTS + 1];
  	struct ttm_placement placement;
 
  	/* restricted by sg_alloc_table */
@@ -849,7 +844,7 @@ static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
  	GEM_BUG_ON(obj->mm.n_placements > I915_TTM_MAX_PLACEMENTS);
 
  	/* Move to the requested placement. */
-	i915_ttm_placement_from_obj(obj, &requested, busy, &placement);
+	i915_ttm_placement_from_obj(obj, places, &placement);
 
  	return __i915_ttm_get_pages(obj, &placement);
  }
@@ -879,9 +874,7 @@ static int __i915_ttm_migrate(struct drm_i915_gem_object *obj,
  	i915_ttm_place_from_region(mr, &requested, obj->bo_offset,
  				   obj->base.size, flags);
  	placement.num_placement = 1;
-	placement.num_busy_placement = 1;
  	placement.placement = &requested;
-	placement.busy_placement = &requested;
 
  	ret = __i915_ttm_get_pages(obj, &placement);
  	if (ret)
drivers/gpu/drm/loongson/lsdc_ttm.c +0 -2
index bf79dc55afa4..465f622ac05d 100644
@@ -54,7 +54,6 @@ static void lsdc_bo_set_placement(struct lsdc_bo *lbo, u32 domain)
  		pflags |= TTM_PL_FLAG_TOPDOWN;
 
  	lbo->placement.placement = lbo->placements;
-	lbo->placement.busy_placement = lbo->placements;
 
  	if (domain & LSDC_GEM_DOMAIN_VRAM) {
  		lbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -77,7 +76,6 @@ static void lsdc_bo_set_placement(struct lsdc_bo *lbo, u32 domain)
  	}
 
  	lbo->placement.num_placement = c;
-	lbo->placement.num_busy_placement = c;
 
  	for (i = 0; i < c; ++i) {
  		lbo->placements[i].fpfn = 0;
drivers/gpu/drm/nouveau/nouveau_bo.c +23 -36
index 00cc7d1abaa3..56dcd25db1ce 100644
@@ -404,27 +404,6 @@ nouveau_bo_new(struct nouveau_cli *cli, u64 size, int align,
  	return 0;
  }
 
-static void
-set_placement_list(struct ttm_place *pl, unsigned *n, uint32_t domain)
-{
-	*n = 0;
-
-	if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
-		pl[*n].mem_type = TTM_PL_VRAM;
-		pl[*n].flags = 0;
-		(*n)++;
-	}
-	if (domain & NOUVEAU_GEM_DOMAIN_GART) {
-		pl[*n].mem_type = TTM_PL_TT;
-		pl[*n].flags = 0;
-		(*n)++;
-	}
-	if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
-		pl[*n].mem_type = TTM_PL_SYSTEM;
-		pl[(*n)++].flags = 0;
-	}
-}
-
  static void
  set_placement_range(struct nouveau_bo *nvbo, uint32_t domain)
  {
@@ -452,10 +431,6 @@ set_placement_range(struct nouveau_bo *nvbo, uint32_t domain)
  			nvbo->placements[i].fpfn = fpfn;
  			nvbo->placements[i].lpfn = lpfn;
  		}
-		for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-			nvbo->busy_placements[i].fpfn = fpfn;
-			nvbo->busy_placements[i].lpfn = lpfn;
-		}
  	}
  }
 
@@ -463,15 +438,32 @@ void
  nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t domain,
  			 uint32_t busy)
  {
-	struct ttm_placement *pl = &nvbo->placement;
+	unsigned int *n = &nvbo->placement.num_placement;
+	struct ttm_place *pl = nvbo->placements;
 
-	pl->placement = nvbo->placements;
-	set_placement_list(nvbo->placements, &pl->num_placement, domain);
+	domain |= busy;
 
-	pl->busy_placement = nvbo->busy_placements;
-	set_placement_list(nvbo->busy_placements, &pl->num_busy_placement,
-			   domain | busy);
+	*n = 0;
+	if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
+		pl[*n].mem_type = TTM_PL_VRAM;
+		pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_VRAM ?
+			TTM_PL_FLAG_FALLBACK : 0;
+		(*n)++;
+	}
+	if (domain & NOUVEAU_GEM_DOMAIN_GART) {
+		pl[*n].mem_type = TTM_PL_TT;
+		pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_GART ?
+			TTM_PL_FLAG_FALLBACK : 0;
+		(*n)++;
+	}
+	if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
+		pl[*n].mem_type = TTM_PL_SYSTEM;
+		pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_CPU ?
+			TTM_PL_FLAG_FALLBACK : 0;
+		(*n)++;
+	}
 
+	nvbo->placement.placement = nvbo->placements;
  	set_placement_range(nvbo, domain);
  }
 
@@ -1314,11 +1306,6 @@ vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
  			nvbo->placements[i].lpfn = mappable;
  		}
 
-		for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-			nvbo->busy_placements[i].fpfn = 0;
-			nvbo->busy_placements[i].lpfn = mappable;
-		}
-
  		nouveau_bo_placement_set(nvbo, NOUVEAU_GEM_DOMAIN_VRAM, 0);
  	}
 
drivers/gpu/drm/nouveau/nouveau_bo.h +0 -1
index 70c551921a9e..e9dfab6a8156 100644
@@ -15,7 +15,6 @@ struct nouveau_bo {
  	struct ttm_placement placement;
  	u32 valid_domains;
  	struct ttm_place placements[3];
-	struct ttm_place busy_placements[3];
  	bool force_coherent;
  	struct ttm_bo_kmap_obj kmap;
  	struct list_head head;
drivers/gpu/drm/qxl/qxl_object.c +0 -2
index 06a58dad5f5c..1e46b0a6e478 100644
@@ -66,7 +66,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain)
  		pflag |= TTM_PL_FLAG_TOPDOWN;
 
  	qbo->placement.placement = qbo->placements;
-	qbo->placement.busy_placement = qbo->placements;
  	if (domain == QXL_GEM_DOMAIN_VRAM) {
  		qbo->placements[c].mem_type = TTM_PL_VRAM;
  		qbo->placements[c++].flags = pflag;
@@ -86,7 +85,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain)
  		qbo->placements[c++].flags = 0;
  	}
  	qbo->placement.num_placement = c;
-	qbo->placement.num_busy_placement = c;
  	for (i = 0; i < c; ++i) {
  		qbo->placements[i].fpfn = 0;
  		qbo->placements[i].lpfn = 0;
drivers/gpu/drm/qxl/qxl_ttm.c +0 -2
index 1a82629bce3f..765a144cea14 100644
@@ -60,9 +60,7 @@ static void qxl_evict_flags(struct ttm_buffer_object *bo,
 
  	if (!qxl_ttm_bo_is_qxl_bo(bo)) {
  		placement->placement = &placements;
-		placement->busy_placement = &placements;
  		placement->num_placement = 1;
-		placement->num_busy_placement = 1;
  		return;
  	}
  	qbo = to_qxl_bo(bo);
drivers/gpu/drm/radeon/radeon_object.c +0 -2
index 10c0fbd9d2b4..a955f8a2f7fe 100644
@@ -78,7 +78,6 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
  	u32 c = 0, i;
 
  	rbo->placement.placement = rbo->placements;
-	rbo->placement.busy_placement = rbo->placements;
  	if (domain & RADEON_GEM_DOMAIN_VRAM) {
  		/* Try placing BOs which don't need CPU access outside of the
  		 * CPU accessible part of VRAM
@@ -114,7 +113,6 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
  	}
 
  	rbo->placement.num_placement = c;
-	rbo->placement.num_busy_placement = c;
 
  	for (i = 0; i < c; ++i) {
  		if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&
drivers/gpu/drm/radeon/radeon_ttm.c +1 -7
index de4e6d78f1e1..2078b0000e22 100644
@@ -92,9 +92,7 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo,
 
  	if (!radeon_ttm_bo_is_radeon_bo(bo)) {
  		placement->placement = &placements;
-		placement->busy_placement = &placements;
  		placement->num_placement = 1;
-		placement->num_busy_placement = 1;
  		return;
  	}
  	rbo = container_of(bo, struct radeon_bo, tbo);
@@ -114,15 +112,11 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo,
  			 */
  			radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_VRAM |
  							 RADEON_GEM_DOMAIN_GTT);
-			rbo->placement.num_busy_placement = 0;
  			for (i = 0; i < rbo->placement.num_placement; i++) {
  				if (rbo->placements[i].mem_type == TTM_PL_VRAM) {
  					if (rbo->placements[i].fpfn < fpfn)
  						rbo->placements[i].fpfn = fpfn;
-				} else {
-					rbo->placement.busy_placement =
-						&rbo->placements[i];
-					rbo->placement.num_busy_placement = 1;
+					rbo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
  				}
  			}
  		} else
drivers/gpu/drm/radeon/radeon_uvd.c +0 -1
index a2cda184b2b2..058a1c8451b2 100644
@@ -324,7 +324,6 @@ void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo,
  	rbo->placements[1].fpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
  	rbo->placements[1].lpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
  	rbo->placement.num_placement++;
-	rbo->placement.num_busy_placement++;
  }
 
  void radeon_uvd_free_handles(struct radeon_device *rdev, struct drm_file *filp)
drivers/gpu/drm/ttm/ttm_bo.c +13 -8
index 8c1eaa74fa21..a5e11a92e0b9 100644
@@ -410,8 +410,8 @@ static int ttm_bo_bounce_temp_buffer(struct ttm_buffer_object *bo,
  	struct ttm_resource *hop_mem;
  	int ret;
 
-	hop_placement.num_placement = hop_placement.num_busy_placement = 1;
-	hop_placement.placement = hop_placement.busy_placement = hop;
+	hop_placement.num_placement = 1;
+	hop_placement.placement = hop;
 
  	/* find space in the bounce domain */
  	ret = ttm_bo_mem_space(bo, &hop_placement, &hop_mem, ctx);
@@ -440,10 +440,9 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
  	dma_resv_assert_held(bo->base.resv);
 
  	placement.num_placement = 0;
-	placement.num_busy_placement = 0;
  	bdev->funcs->evict_flags(bo, &placement);
 
-	if (!placement.num_placement && !placement.num_busy_placement) {
+	if (!placement.num_placement) {
  		ret = ttm_bo_wait_ctx(bo, ctx);
  		if (ret)
  			return ret;
@@ -791,6 +790,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
  		const struct ttm_place *place = &placement->placement[i];
  		struct ttm_resource_manager *man;
 
+		if (place->flags & TTM_PL_FLAG_FALLBACK)
+			continue;
+
  		man = ttm_manager_type(bdev, place->mem_type);
  		if (!man || !ttm_resource_manager_used(man))
  			continue;
@@ -813,10 +815,13 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
  		return 0;
  	}
 
-	for (i = 0; i < placement->num_busy_placement; ++i) {
-		const struct ttm_place *place = &placement->busy_placement[i];
+	for (i = 0; i < placement->num_placement; ++i) {
+		const struct ttm_place *place = &placement->placement[i];
  		struct ttm_resource_manager *man;
 
+		if (place->flags & TTM_PL_FLAG_DESIRED)
+			continue;
+
  		man = ttm_manager_type(bdev, place->mem_type);
  		if (!man || !ttm_resource_manager_used(man))
  			continue;
@@ -904,11 +909,11 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
  	/*
  	 * Remove the backing store if no placement is given.
  	 */
-	if (!placement->num_placement && !placement->num_busy_placement)
+	if (!placement->num_placement)
  		return ttm_bo_pipeline_gutting(bo);
 
  	/* Check whether we need to move buffer. */
-	if (bo->resource && ttm_resource_compat(bo->resource, placement))
+	if (bo->resource && ttm_resource_compatible(bo->resource, placement))
  		return 0;
 
  	/* Moving of pinned BOs is forbidden */
drivers/gpu/drm/ttm/ttm_resource.c +16 -57
index 02b96d23fdb9..fb14f7716cf8 100644
@@ -291,37 +291,15 @@ bool ttm_resource_intersects(struct ttm_device *bdev,
  }
 
  /**
- * ttm_resource_compatible - test for compatibility
+ * ttm_resource_compatible - check if resource is compatible with placement
   *
- * @bdev: TTM device structure
- * @res: The resource to test
- * @place: The placement to test
- * @size: How many bytes the new allocation needs.
- *
- * Test if @res compatible with @place and @size.
+ * @res: the resource to check
+ * @placement: the placement to check against
   *
- * Returns true if the res placement compatible with @place and @size.
+ * Returns true if the placement is compatible.
   */
-bool ttm_resource_compatible(struct ttm_device *bdev,
-			     struct ttm_resource *res,
-			     const struct ttm_place *place,
-			     size_t size)
-{
-	struct ttm_resource_manager *man;
-
-	if (!res || !place)
-		return false;
-
-	man = ttm_manager_type(bdev, res->mem_type);
-	if (!man->func->compatible)
-		return true;
-
-	return man->func->compatible(man, res, place, size);
-}
-
-static bool ttm_resource_places_compat(struct ttm_resource *res,
-				       const struct ttm_place *places,
-				       unsigned num_placement)
+bool ttm_resource_compatible(struct ttm_resource *res,
+			     struct ttm_placement *placement)
  {
  	struct ttm_buffer_object *bo = res->bo;
  	struct ttm_device *bdev = bo->bdev;
@@ -330,44 +308,25 @@ static bool ttm_resource_places_compat(struct ttm_resource *res,
  	if (res->placement & TTM_PL_FLAG_TEMPORARY)
  		return false;
 
-	for (i = 0; i < num_placement; i++) {
-		const struct ttm_place *heap = &places[i];
+	for (i = 0; i < placement->num_placement; i++) {
+		const struct ttm_place *place = &placement->placement[i];
+		struct ttm_resource_manager *man;
 
-		if (!ttm_resource_compatible(bdev, res, heap, bo->base.size))
+		if (res->mem_type != place->mem_type)
+			continue;
+
+		man = ttm_manager_type(bdev, res->mem_type);
+		if (man->func->compatible &&
+		    !man->func->compatible(man, res, place, bo->base.size))
  			continue;
 
-		if ((res->mem_type == heap->mem_type) &&
-		    (!(heap->flags & TTM_PL_FLAG_CONTIGUOUS) ||
+		if ((!(place->flags & TTM_PL_FLAG_CONTIGUOUS) ||
  		     (res->placement & TTM_PL_FLAG_CONTIGUOUS)))
  			return true;
  	}
  	return false;
  }
 
-/**
- * ttm_resource_compat - check if resource is compatible with placement
- *
- * @res: the resource to check
- * @placement: the placement to check against
- *
- * Returns true if the placement is compatible.
- */
-bool ttm_resource_compat(struct ttm_resource *res,
-			 struct ttm_placement *placement)
-{
-	if (ttm_resource_places_compat(res, placement->placement,
-				       placement->num_placement))
-		return true;
-
-	if ((placement->busy_placement != placement->placement ||
-	     placement->num_busy_placement > placement->num_placement) &&
-	    ttm_resource_places_compat(res, placement->busy_placement,
-				       placement->num_busy_placement))
-		return true;
-
-	return false;
-}
-
  void ttm_resource_set_bo(struct ttm_resource *res,
  			 struct ttm_buffer_object *bo)
  {
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +24 -9
index 2bfac3aad7b7..bfd41ce3c8f4 100644
@@ -742,9 +742,21 @@ void vmw_bo_move_notify(struct ttm_buffer_object *bo,
  		vmw_resource_unbind_list(vbo);
  }
 
+static u32 placement_flags(u32 domain, u32 desired, u32 fallback)
+{
+	if (desired & fallback & domain)
+		return 0;
+
+	if (desired & domain)
+		return TTM_PL_FLAG_DESIRED;
+
+	return TTM_PL_FLAG_FALLBACK;
+}
+
  static u32
-set_placement_list(struct ttm_place *pl, u32 domain)
+set_placement_list(struct ttm_place *pl, u32 desired, u32 fallback)
  {
+	u32 domain = desired | fallback;
  	u32 n = 0;
 
  	/*
@@ -752,35 +764,40 @@ set_placement_list(struct ttm_place *pl, u32 domain)
  	 */
  	if (domain & VMW_BO_DOMAIN_MOB) {
  		pl[n].mem_type = VMW_PL_MOB;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_MOB, desired,
+					      fallback);
  		pl[n].fpfn = 0;
  		pl[n].lpfn = 0;
  		n++;
  	}
  	if (domain & VMW_BO_DOMAIN_GMR) {
  		pl[n].mem_type = VMW_PL_GMR;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_GMR, desired,
+					      fallback);
  		pl[n].fpfn = 0;
  		pl[n].lpfn = 0;
  		n++;
  	}
  	if (domain & VMW_BO_DOMAIN_VRAM) {
  		pl[n].mem_type = TTM_PL_VRAM;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_VRAM, desired,
+					      fallback);
  		pl[n].fpfn = 0;
  		pl[n].lpfn = 0;
  		n++;
  	}
  	if (domain & VMW_BO_DOMAIN_WAITABLE_SYS) {
  		pl[n].mem_type = VMW_PL_SYSTEM;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_WAITABLE_SYS,
+					      desired, fallback);
  		pl[n].fpfn = 0;
  		pl[n].lpfn = 0;
  		n++;
  	}
  	if (domain & VMW_BO_DOMAIN_SYS) {
  		pl[n].mem_type = TTM_PL_SYSTEM;
-		pl[n].flags = 0;
+		pl[n].flags = placement_flags(VMW_BO_DOMAIN_SYS, desired,
+					      fallback);
  		pl[n].fpfn = 0;
  		pl[n].lpfn = 0;
  		n++;
@@ -806,7 +823,7 @@ void vmw_bo_placement_set(struct vmw_bo *bo, u32 domain, u32 busy_domain)
  	u32 i;
 
  	pl->placement = bo->places;
-	pl->num_placement = set_placement_list(bo->places, domain);
+	pl->num_placement = set_placement_list(bo->places, domain, busy_domain);
 
  	if (drm_debug_enabled(DRM_UT_DRIVER) && bo->tbo.resource) {
  		for (i = 0; i < pl->num_placement; ++i) {
@@ -821,8 +838,6 @@ void vmw_bo_placement_set(struct vmw_bo *bo, u32 domain, u32 busy_domain)
  				 __func__, bo->tbo.resource->mem_type, domain);
  	}
 
-	pl->busy_placement = bo->busy_places;
-	pl->num_busy_placement = set_placement_list(bo->busy_places, busy_domain);
  }
 
  void vmw_bo_placement_set_default_accelerated(struct vmw_bo *bo)
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +0 -4
index a84fffcef8e1..4d23d0a70bcb 100644
@@ -46,15 +46,11 @@ static const struct ttm_place sys_placement_flags = {
  struct ttm_placement vmw_vram_placement = {
  	.num_placement = 1,
  	.placement = &vram_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &vram_placement_flags
  };
 
  struct ttm_placement vmw_sys_placement = {
  	.num_placement = 1,
  	.placement = &sys_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags
  };
 
  const size_t vmw_tt_size = sizeof(struct vmw_ttm_tt);
drivers/gpu/drm/xe/xe_bo.c +15 -18
index 8e4a3b1f6b93..1e5edc7f0b85 100644
@@ -38,22 +38,26 @@ static const struct ttm_place sys_placement_flags = {
  static struct ttm_placement sys_placement = {
  	.num_placement = 1,
  	.placement = &sys_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags,
  };
 
-static const struct ttm_place tt_placement_flags = {
-	.fpfn = 0,
-	.lpfn = 0,
-	.mem_type = XE_PL_TT,
-	.flags = 0,
+static const struct ttm_place tt_placement_flags[] = {
+	{
+		.fpfn = 0,
+		.lpfn = 0,
+		.mem_type = XE_PL_TT,
+		.flags = TTM_PL_FLAG_DESIRED,
+	},
+	{
+		.fpfn = 0,
+		.lpfn = 0,
+		.mem_type = XE_PL_SYSTEM,
+		.flags = TTM_PL_FLAG_FALLBACK,
+	}
  };
 
  static struct ttm_placement tt_placement = {
-	.num_placement = 1,
-	.placement = &tt_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags,
+	.num_placement = 2,
+	.placement = tt_placement_flags,
  };
 
  bool mem_type_is_vram(u32 mem_type)
@@ -230,8 +234,6 @@ static int __xe_bo_placement_for_flags(struct xe_device *xe, struct xe_bo *bo,
  	bo->placement = (struct ttm_placement) {
  		.num_placement = c,
  		.placement = bo->placements,
-		.num_busy_placement = c,
-		.busy_placement = bo->placements,
  	};
 
  	return 0;
@@ -251,7 +253,6 @@ static void xe_evict_flags(struct ttm_buffer_object *tbo,
  		/* Don't handle scatter gather BOs */
  		if (tbo->type == ttm_bo_type_sg) {
  			placement->num_placement = 0;
-			placement->num_busy_placement = 0;
  			return;
  		}
 
@@ -1353,8 +1354,6 @@ static int __xe_bo_fixed_placement(struct xe_device *xe,
  	bo->placement = (struct ttm_placement) {
  		.num_placement = 1,
  		.placement = place,
-		.num_busy_placement = 1,
-		.busy_placement = place,
  	};
 
  	return 0;
@@ -2112,9 +2111,7 @@ int xe_bo_migrate(struct xe_bo *bo, u32 mem_type)
 
  	xe_place_from_ttm_type(mem_type, &requested);
  	placement.num_placement = 1;
-	placement.num_busy_placement = 1;
  	placement.placement = &requested;
-	placement.busy_placement = &requested;
 
  	/*
  	 * Stolen needs to be handled like below VRAM handling if we ever need
include/drm/ttm/ttm_placement.h +6 -4
index 8074d0f6cae5..b510a4812609 100644
@@ -64,6 +64,12 @@
  /* For multihop handling */
  #define TTM_PL_FLAG_TEMPORARY   (1 << 2)
 
+/* Placement is never used during eviction */
+#define TTM_PL_FLAG_DESIRED	(1 << 3)
+
+/* Placement is only used during eviction */
+#define TTM_PL_FLAG_FALLBACK	(1 << 4)
+
  /**
   * struct ttm_place
   *
@@ -86,16 +92,12 @@ struct ttm_place {
   *
   * @num_placement:	number of preferred placements
   * @placement:		preferred placements
- * @num_busy_placement:	number of preferred placements when need to evict buffer
- * @busy_placement:	preferred placements when need to evict buffer
   *
   * Structure indicating the placement you request for an object.
   */
  struct ttm_placement {
  	unsigned		num_placement;
  	const struct ttm_place	*placement;
-	unsigned		num_busy_placement;
-	const struct ttm_place	*busy_placement;
  };
 
  #endif
include/drm/ttm/ttm_resource.h +2 -6
index 78a226eba953..1afa13f0c22b 100644
@@ -365,12 +365,8 @@ bool ttm_resource_intersects(struct ttm_device *bdev,
  			     struct ttm_resource *res,
  			     const struct ttm_place *place,
  			     size_t size);
-bool ttm_resource_compatible(struct ttm_device *bdev,
-			     struct ttm_resource *res,
-			     const struct ttm_place *place,
-			     size_t size);
-bool ttm_resource_compat(struct ttm_resource *res,
-			 struct ttm_placement *placement);
+bool ttm_resource_compatible(struct ttm_resource *res,
+			     struct ttm_placement *placement);
  void ttm_resource_set_bo(struct ttm_resource *res,
  			 struct ttm_buffer_object *bo);
 
#7 lore raw

Re: [PATCH 3/5] drm/ttm: replace busy placement with flags v6

Quoted 3 lines · Thomas Hellström

Hi, Christian

Xe changes look good. Will send the series to xe ci to check for regressions.

Hmm, there are some checkpatch warnings about author / SOB email mismatch,

But worserthere are some regressions in the dma-buf ktest (it tests evicting of a dynamic dma-buf),

https://patchwork.freedesktop.org/series/128873/

I'll take a look later today or tomorrow.

/Thomas

Quoted 855 lines

/Thomas

Quoted 850 lines · Christian König

From: Somalapuram Amaranath <[email protected]>

Instead of a list of separate busy placement add flags which indicate that a placement should only be used when there is room or if we need to evict.

v2: add missing TTM_PL_FLAG_IDLE for i915
v3: fix auto build test ERROR on drm-tip/drm-tip
v4: fix some typos pointed out by checkpatch
v5: cleanup some rebase problems with VMWGFX
v6: implement some missing VMWGFX functionality pointed out by Zack, rename the flags as suggested by Michel, rebase on drm-tip and adjust XE as well

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |  6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 11 +--- drivers/gpu/drm/drm_gem_vram_helper.c      |  2 - drivers/gpu/drm/i915/gem/i915_gem_ttm.c    | 37 +++++------ drivers/gpu/drm/loongson/lsdc_ttm.c        |  2 - drivers/gpu/drm/nouveau/nouveau_bo.c       | 59 +++++++---------- drivers/gpu/drm/nouveau/nouveau_bo.h       |  1 - drivers/gpu/drm/qxl/qxl_object.c           |  2 - drivers/gpu/drm/qxl/qxl_ttm.c              |  2 - drivers/gpu/drm/radeon/radeon_object.c     |  2 - drivers/gpu/drm/radeon/radeon_ttm.c        |  8 +-- drivers/gpu/drm/radeon/radeon_uvd.c        |  1 - drivers/gpu/drm/ttm/ttm_bo.c               | 21 ++++--- drivers/gpu/drm/ttm/ttm_resource.c         | 73 +++++----------------- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c         | 33 +++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c |  4 -- drivers/gpu/drm/xe/xe_bo.c                 | 33 +++++----- include/drm/ttm/ttm_placement.h            | 10 +-- include/drm/ttm/ttm_resource.h             |  8 +--

  19 files changed, 118 insertions(+), 197 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -5
index 425cebcc5cbf..b671b0665492 100644
@@ -220,9 +220,6 @@ void amdgpu_bo_placement_from_domain(struct 
 amdgpu_bo *abo, u32 domain)
         placement->num_placement = c;
       placement->placement = places;
-
-    placement->num_busy_placement = c;
-    placement->busy_placement = places;
   }
     /**
@@ -1397,8 +1394,7 @@ vm_fault_t 
 amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
                       AMDGPU_GEM_DOMAIN_GTT);
         /* Avoid costly evictions; only set GTT as a busy placement */
-    abo->placement.num_busy_placement = 1;
-    abo->placement.busy_placement = &abo->placements[1];
+    abo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
         r = ttm_bo_validate(bo, &abo->placement, &ctx);
       if (unlikely(r == -EBUSY || r == -ERESTARTSYS))
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -4
index 75c9fd2c6c2a..8722beba494e 100644
@@ -102,23 +102,19 @@ static void amdgpu_evict_flags(struct 
 ttm_buffer_object *bo,
       /* Don't handle scatter gather BOs */
       if (bo->type == ttm_bo_type_sg) {
           placement->num_placement = 0;
-        placement->num_busy_placement = 0;
           return;
       }
         /* Object isn't an AMDGPU object so ignore */
       if (!amdgpu_bo_is_amdgpu_bo(bo)) {
           placement->placement = &placements;
-        placement->busy_placement = &placements;
           placement->num_placement = 1;
-        placement->num_busy_placement = 1;
           return;
       }
         abo = ttm_to_amdgpu_bo(bo);
       if (abo->flags & AMDGPU_GEM_CREATE_DISCARDABLE) {
           placement->num_placement = 0;
-        placement->num_busy_placement = 0;
           return;
       }
   @@ -128,13 +124,13 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,

      case AMDGPU_PL_OA:
      case AMDGPU_PL_DOORBELL:
          placement->num_placement = 0;
-        placement->num_busy_placement = 0;
          return;
        case TTM_PL_VRAM:
          if (!adev->mman.buffer_funcs_enabled) {
              /* Move to system memory */ amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_CPU); +
          } else if (!amdgpu_gmc_vram_full_visible(&adev->gmc) && !(abo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) && amdgpu_bo_in_cpu_visible_vram(abo)) {

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
@@ -149,8 +145,7 @@ static void amdgpu_evict_flags(struct 
 ttm_buffer_object *bo,
                               AMDGPU_GEM_DOMAIN_CPU);

              abo->placements[0].fpfn = adev->gmc.visible_vram_size

Quoted 1 line
Quoted 1 line

PAGE_SHIFT;

              abo->placements[0].lpfn = 0;
-            abo->placement.busy_placement = &abo->placements[1]; -            abo->placement.num_busy_placement = 1;
+            abo->placements[0].flags |= TTM_PL_FLAG_DESIRED; } else {
              /* Move to GTT memory */ amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT |

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -2
@@ -966,8 +961,6 @@ int amdgpu_ttm_alloc_gart(struct 
 ttm_buffer_object *bo)
       /* allocate GART space */
       placement.num_placement = 1;
       placement.placement = &placements;
-    placement.num_busy_placement = 1;
-    placement.busy_placement = &placements;
       placements.fpfn = 0;
       placements.lpfn = adev->gmc.gart_size >> PAGE_SHIFT;

      placements.mem_type = TTM_PL_TT;

drivers/gpu/drm/drm_gem_vram_helper.c +0 -2
index b67eafa55715..75f2eaf0d5b6 100644
@@ -147,7 +147,6 @@ static void drm_gem_vram_placement(struct 
 drm_gem_vram_object *gbo,
           invariant_flags = TTM_PL_FLAG_TOPDOWN;
         gbo->placement.placement = gbo->placements;
-    gbo->placement.busy_placement = gbo->placements;
         if (pl_flag & DRM_GEM_VRAM_PL_FLAG_VRAM) {
           gbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -160,7 +159,6 @@ static void drm_gem_vram_placement(struct 
 drm_gem_vram_object *gbo,
       }
         gbo->placement.num_placement = c;
-    gbo->placement.num_busy_placement = c;
         for (i = 0; i < c; ++i) {
           gbo->placements[i].fpfn = 0;
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -2
index 6b69ef0cdbb4..80c6cafc8887 100644
@@ -65,8 +65,6 @@ static const struct ttm_place sys_placement_flags = {
   static struct ttm_placement i915_sys_placement = {
       .num_placement = 1,
       .placement = &sys_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &sys_placement_flags,
   };
     /**
@@ -157,32 +155,28 @@ i915_ttm_place_from_region(const struct 
 intel_memory_region *mr,

    static void
  i915_ttm_placement_from_obj(const struct drm_i915_gem_object *obj, -                struct ttm_place *requested,
-                struct ttm_place *busy,
+                struct ttm_place *places,
                  struct ttm_placement *placement)
  {
      unsigned int num_allowed = obj->mm.n_placements; unsigned int flags = obj->flags;
      unsigned int i;
  -    placement->num_placement = 1;
+    places[0].flags |= TTM_PL_FLAG_DESIRED; i915_ttm_place_from_region(num_allowed ? obj->mm.placements[0] :
-                   obj->mm.region, requested, obj->bo_offset, +                   obj->mm.region, &places[0], obj->bo_offset, obj->base.size, flags);
        /* Cache this on object? */
-    placement->num_busy_placement = num_allowed;
-    for (i = 0; i < placement->num_busy_placement; ++i)
-        i915_ttm_place_from_region(obj->mm.placements[i], busy + i, -                       obj->bo_offset, obj->base.size, flags); -
-    if (num_allowed == 0) {
-        *busy = *requested;
-        placement->num_busy_placement = 1;
+    for (i = 0; i < num_allowed; ++i) {
+        i915_ttm_place_from_region(obj->mm.placements[i], +                       &places[i + 1], obj->bo_offset,
+                       obj->base.size, flags);
+        places[i + 1].flags |= TTM_PL_FLAG_FALLBACK;
      }
  -    placement->placement = requested;
-    placement->busy_placement = busy;
+    placement->num_placement = num_allowed + 1;
+    placement->placement = places;
  }
    static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev,

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +3 -2
@@ -789,7 +783,8 @@ static int __i915_ttm_get_pages(struct 
 drm_i915_gem_object *obj,
       int ret;
         /* First try only the requested placement. No eviction. */
-    real_num_busy = fetch_and_zero(&placement->num_busy_placement);
+    real_num_busy = placement->num_placement;
+    placement->num_placement = 1;
       ret = ttm_bo_validate(bo, placement, &ctx);
       if (ret) {
           ret = i915_ttm_err_to_gem(ret);
@@ -805,7 +800,7 @@ static int __i915_ttm_get_pages(struct 
 drm_i915_gem_object *obj,
            * If the initial attempt fails, allow all accepted placements,
            * evicting if necessary.
            */
-        placement->num_busy_placement = real_num_busy;
+        placement->num_placement = real_num_busy;
           ret = ttm_bo_validate(bo, placement, &ctx);
           if (ret)

              return i915_ttm_err_to_gem(ret);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -4
@@ -839,7 +834,7 @@ static int __i915_ttm_get_pages(struct 
 drm_i915_gem_object *obj,
     static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
   {
-    struct ttm_place requested, busy[I915_TTM_MAX_PLACEMENTS];
+    struct ttm_place places[I915_TTM_MAX_PLACEMENTS + 1];
       struct ttm_placement placement;
         /* restricted by sg_alloc_table */
@@ -849,7 +844,7 @@ static int i915_ttm_get_pages(struct 
 drm_i915_gem_object *obj)
       GEM_BUG_ON(obj->mm.n_placements > I915_TTM_MAX_PLACEMENTS);
         /* Move to the requested placement. */
-    i915_ttm_placement_from_obj(obj, &requested, busy, &placement);
+    i915_ttm_placement_from_obj(obj, places, &placement);
         return __i915_ttm_get_pages(obj, &placement);
   }
@@ -879,9 +874,7 @@ static int __i915_ttm_migrate(struct 
 drm_i915_gem_object *obj,
       i915_ttm_place_from_region(mr, &requested, obj->bo_offset,
                      obj->base.size, flags);
       placement.num_placement = 1;
-    placement.num_busy_placement = 1;
       placement.placement = &requested;
-    placement.busy_placement = &requested;
         ret = __i915_ttm_get_pages(obj, &placement);
       if (ret)
drivers/gpu/drm/loongson/lsdc_ttm.c +0 -2
index bf79dc55afa4..465f622ac05d 100644
@@ -54,7 +54,6 @@ static void lsdc_bo_set_placement(struct lsdc_bo 
 *lbo, u32 domain)
           pflags |= TTM_PL_FLAG_TOPDOWN;
         lbo->placement.placement = lbo->placements;
-    lbo->placement.busy_placement = lbo->placements;
         if (domain & LSDC_GEM_DOMAIN_VRAM) {
           lbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -77,7 +76,6 @@ static void lsdc_bo_set_placement(struct lsdc_bo 
 *lbo, u32 domain)
       }
         lbo->placement.num_placement = c;
-    lbo->placement.num_busy_placement = c;
         for (i = 0; i < c; ++i) {
           lbo->placements[i].fpfn = 0;
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -0
index 00cc7d1abaa3..56dcd25db1ce 100644
@@ -404,27 +404,6 @@ nouveau_bo_new(struct nouveau_cli *cli, u64 
 size, int align,
       return 0;
   }

  -static void

drivers/gpu/drm/nouveau/nouveau_bo.c +0 -20
-set_placement_list(struct ttm_place *pl, unsigned *n, uint32_t domain)
-{
-    *n = 0;
-
-    if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
-        pl[*n].mem_type = TTM_PL_VRAM;
-        pl[*n].flags = 0;
-        (*n)++;
-    }
-    if (domain & NOUVEAU_GEM_DOMAIN_GART) {
-        pl[*n].mem_type = TTM_PL_TT;
-        pl[*n].flags = 0;
-        (*n)++;
-    }
-    if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
-        pl[*n].mem_type = TTM_PL_SYSTEM;
-        pl[(*n)++].flags = 0;
-    }
-}
-

  static void
  set_placement_range(struct nouveau_bo *nvbo, uint32_t domain) {

drivers/gpu/drm/nouveau/nouveau_bo.c +0 -4
@@ -452,10 +431,6 @@ set_placement_range(struct nouveau_bo *nvbo, 
 uint32_t domain)
               nvbo->placements[i].fpfn = fpfn;
               nvbo->placements[i].lpfn = lpfn;
           }
-        for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-            nvbo->busy_placements[i].fpfn = fpfn;
-            nvbo->busy_placements[i].lpfn = lpfn;
-        }
       }
   }

  @@ -463,15 +438,32 @@ void
  nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t domain,
               uint32_t busy)
  {
-    struct ttm_placement *pl = &nvbo->placement;
+    unsigned int *n = &nvbo->placement.num_placement;
+    struct ttm_place *pl = nvbo->placements;
  -    pl->placement = nvbo->placements;
-    set_placement_list(nvbo->placements, &pl->num_placement, domain);
+    domain |= busy;
  -    pl->busy_placement = nvbo->busy_placements;
-    set_placement_list(nvbo->busy_placements, &pl->num_busy_placement,
-               domain | busy);
+    *n = 0;
+    if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
+        pl[*n].mem_type = TTM_PL_VRAM;
+        pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_VRAM ?
+            TTM_PL_FLAG_FALLBACK : 0;
+        (*n)++;
+    }
+    if (domain & NOUVEAU_GEM_DOMAIN_GART) {
+        pl[*n].mem_type = TTM_PL_TT;
+        pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_GART ?
+            TTM_PL_FLAG_FALLBACK : 0;
+        (*n)++;
+    }
+    if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
+        pl[*n].mem_type = TTM_PL_SYSTEM;
+        pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_CPU ?
+            TTM_PL_FLAG_FALLBACK : 0;
+        (*n)++;
+    }
  +    nvbo->placement.placement = nvbo->placements;
      set_placement_range(nvbo, domain);
  }
  @@ -1314,11 +1306,6 @@ vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo) nvbo->placements[i].lpfn = mappable;
          }
  -        for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-            nvbo->busy_placements[i].fpfn = 0;
-            nvbo->busy_placements[i].lpfn = mappable;
-        }
-
          nouveau_bo_placement_set(nvbo, NOUVEAU_GEM_DOMAIN_VRAM, 0);
      }
  diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.h b/drivers/gpu/drm/nouveau/nouveau_bo.h index 70c551921a9e..e9dfab6a8156 100644

drivers/gpu/drm/nouveau/nouveau_bo.h +0 -1
@@ -15,7 +15,6 @@ struct nouveau_bo {
       struct ttm_placement placement;
       u32 valid_domains;
       struct ttm_place placements[3];
-    struct ttm_place busy_placements[3];
       bool force_coherent;
       struct ttm_bo_kmap_obj kmap;
       struct list_head head;
drivers/gpu/drm/qxl/qxl_object.c +0 -2
index 06a58dad5f5c..1e46b0a6e478 100644
@@ -66,7 +66,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo 
 *qbo, u32 domain)
           pflag |= TTM_PL_FLAG_TOPDOWN;
         qbo->placement.placement = qbo->placements;
-    qbo->placement.busy_placement = qbo->placements;
       if (domain == QXL_GEM_DOMAIN_VRAM) {
           qbo->placements[c].mem_type = TTM_PL_VRAM;
           qbo->placements[c++].flags = pflag;
@@ -86,7 +85,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo 
 *qbo, u32 domain)
           qbo->placements[c++].flags = 0;
       }
       qbo->placement.num_placement = c;
-    qbo->placement.num_busy_placement = c;
       for (i = 0; i < c; ++i) {
           qbo->placements[i].fpfn = 0;

          qbo->placements[i].lpfn = 0;

drivers/gpu/drm/qxl/qxl_ttm.c +0 -2
index 1a82629bce3f..765a144cea14 100644
@@ -60,9 +60,7 @@ static void qxl_evict_flags(struct 
 ttm_buffer_object *bo,
         if (!qxl_ttm_bo_is_qxl_bo(bo)) {
           placement->placement = &placements;
-        placement->busy_placement = &placements;
           placement->num_placement = 1;
-        placement->num_busy_placement = 1;
           return;
       }
       qbo = to_qxl_bo(bo);
drivers/gpu/drm/radeon/radeon_object.c +0 -2
index 10c0fbd9d2b4..a955f8a2f7fe 100644
@@ -78,7 +78,6 @@ void radeon_ttm_placement_from_domain(struct 
 radeon_bo *rbo, u32 domain)
       u32 c = 0, i;
         rbo->placement.placement = rbo->placements;
-    rbo->placement.busy_placement = rbo->placements;
       if (domain & RADEON_GEM_DOMAIN_VRAM) {
           /* Try placing BOs which don't need CPU access outside of the
            * CPU accessible part of VRAM
@@ -114,7 +113,6 @@ void radeon_ttm_placement_from_domain(struct 
 radeon_bo *rbo, u32 domain)
       }
         rbo->placement.num_placement = c;
-    rbo->placement.num_busy_placement = c;
         for (i = 0; i < c; ++i) {

          if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&

drivers/gpu/drm/radeon/radeon_ttm.c +0 -2
index de4e6d78f1e1..2078b0000e22 100644
@@ -92,9 +92,7 @@ static void radeon_evict_flags(struct 
 ttm_buffer_object *bo,
         if (!radeon_ttm_bo_is_radeon_bo(bo)) {
           placement->placement = &placements;
-        placement->busy_placement = &placements;
           placement->num_placement = 1;
-        placement->num_busy_placement = 1;
           return;
       }
       rbo = container_of(bo, struct radeon_bo, tbo);
@@ -114,15 +112,11 @@ static void radeon_evict_flags(struct 
 ttm_buffer_object *bo,
                */

              radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_VRAM | RADEON_GEM_DOMAIN_GTT);
-            rbo->placement.num_busy_placement = 0;
              for (i = 0; i < rbo->placement.num_placement; i++) { if (rbo->placements[i].mem_type == TTM_PL_VRAM) { if (rbo->placements[i].fpfn < fpfn) rbo->placements[i].fpfn = fpfn;
-                } else {
-                    rbo->placement.busy_placement =
-                        &rbo->placements[i];
-                    rbo->placement.num_busy_placement = 1;
+                    rbo->placements[0].flags |= TTM_PL_FLAG_DESIRED; }
              }
          } else

drivers/gpu/drm/radeon/radeon_uvd.c +0 -1
index a2cda184b2b2..058a1c8451b2 100644
@@ -324,7 +324,6 @@ void radeon_uvd_force_into_uvd_segment(struct 
 radeon_bo *rbo,
       rbo->placements[1].fpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
       rbo->placements[1].lpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
       rbo->placement.num_placement++;
-    rbo->placement.num_busy_placement++;
   }
     void radeon_uvd_free_handles(struct radeon_device *rdev, struct drm_file *filp)
drivers/gpu/drm/ttm/ttm_bo.c +11 -5
index 8c1eaa74fa21..a5e11a92e0b9 100644
@@ -410,8 +410,8 @@ static int ttm_bo_bounce_temp_buffer(struct 
 ttm_buffer_object *bo,
       struct ttm_resource *hop_mem;
       int ret;
   -    hop_placement.num_placement = hop_placement.num_busy_placement = 1;
-    hop_placement.placement = hop_placement.busy_placement = hop;
+    hop_placement.num_placement = 1;
+    hop_placement.placement = hop;
         /* find space in the bounce domain */
       ret = ttm_bo_mem_space(bo, &hop_placement, &hop_mem, ctx);
@@ -440,10 +440,9 @@ static int ttm_bo_evict(struct ttm_buffer_object 
 *bo,
       dma_resv_assert_held(bo->base.resv);
         placement.num_placement = 0;
-    placement.num_busy_placement = 0;
       bdev->funcs->evict_flags(bo, &placement);
   -    if (!placement.num_placement && !placement.num_busy_placement) {
+    if (!placement.num_placement) {
           ret = ttm_bo_wait_ctx(bo, ctx);
           if (ret)
               return ret;
@@ -791,6 +790,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
           const struct ttm_place *place = &placement->placement[i];
           struct ttm_resource_manager *man;
   +        if (place->flags & TTM_PL_FLAG_FALLBACK)
+            continue;
+
           man = ttm_manager_type(bdev, place->mem_type);
           if (!man || !ttm_resource_manager_used(man))
               continue;
@@ -813,10 +815,13 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
           return 0;
       }
   -    for (i = 0; i < placement->num_busy_placement; ++i) {
-        const struct ttm_place *place = &placement->busy_placement[i];
+    for (i = 0; i < placement->num_placement; ++i) {
+        const struct ttm_place *place = &placement->placement[i];
           struct ttm_resource_manager *man;
   +        if (place->flags & TTM_PL_FLAG_DESIRED)
+            continue;
+
           man = ttm_manager_type(bdev, place->mem_type);
           if (!man || !ttm_resource_manager_used(man))
               continue;
@@ -904,11 +909,11 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
       /*
        * Remove the backing store if no placement is given.
        */
-    if (!placement->num_placement && !placement->num_busy_placement)
+    if (!placement->num_placement)
           return ttm_bo_pipeline_gutting(bo);
         /* Check whether we need to move buffer. */
-    if (bo->resource && ttm_resource_compat(bo->resource, placement))
+    if (bo->resource && ttm_resource_compatible(bo->resource, 
 placement))
           return 0;
         /* Moving of pinned BOs is forbidden */
drivers/gpu/drm/ttm/ttm_resource.c +1 -1
index 02b96d23fdb9..fb14f7716cf8 100644
@@ -291,37 +291,15 @@ bool ttm_resource_intersects(struct ttm_device 
 *bdev,
   }
     /**
- * ttm_resource_compatible - test for compatibility
+ * ttm_resource_compatible - check if resource is compatible with 

placement
   *
- * @bdev: TTM device structure
- * @res: The resource to test
- * @place: The placement to test
- * @size: How many bytes the new allocation needs.
- *
- * Test if @res compatible with @place and @size.
+ * @res: the resource to check
+ * @placement: the placement to check against
   *
- * Returns true if the res placement compatible with @place and @size.
+ * Returns true if the placement is compatible.
   */

drivers/gpu/drm/ttm/ttm_resource.c +2 -20
-bool ttm_resource_compatible(struct ttm_device *bdev,
-                 struct ttm_resource *res,
-                 const struct ttm_place *place,
-                 size_t size)
-{
-    struct ttm_resource_manager *man;
-
-    if (!res || !place)
-        return false;
-
-    man = ttm_manager_type(bdev, res->mem_type);
-    if (!man->func->compatible)
-        return true;
-
-    return man->func->compatible(man, res, place, size);
-}
-
-static bool ttm_resource_places_compat(struct ttm_resource *res,
-                       const struct ttm_place *places,
-                       unsigned num_placement)
+bool ttm_resource_compatible(struct ttm_resource *res,
+                 struct ttm_placement *placement)

  {
      struct ttm_buffer_object *bo = res->bo;
      struct ttm_device *bdev = bo->bdev;

drivers/gpu/drm/ttm/ttm_resource.c +9 -1
@@ -330,44 +308,25 @@ static bool ttm_resource_places_compat(struct 
 ttm_resource *res,
       if (res->placement & TTM_PL_FLAG_TEMPORARY)
           return false;
   -    for (i = 0; i < num_placement; i++) {
-        const struct ttm_place *heap = &places[i];
+    for (i = 0; i < placement->num_placement; i++) {
+        const struct ttm_place *place = &placement->placement[i];
+        struct ttm_resource_manager *man;
   -        if (!ttm_resource_compatible(bdev, res, heap, bo->base.size))
+        if (res->mem_type != place->mem_type)
+            continue;
+
+        man = ttm_manager_type(bdev, res->mem_type);
+        if (man->func->compatible &&
+            !man->func->compatible(man, res, place, bo->base.size))
               continue;

  -        if ((res->mem_type == heap->mem_type) &&
-            (!(heap->flags & TTM_PL_FLAG_CONTIGUOUS) ||
+        if ((!(place->flags & TTM_PL_FLAG_CONTIGUOUS) || (res->placement & TTM_PL_FLAG_CONTIGUOUS))) return true;
      }
      return false;
  }
  -/**
- * ttm_resource_compat - check if resource is compatible with placement
- *
- * @res: the resource to check
- * @placement: the placement to check against
- *
- * Returns true if the placement is compatible.
- */

drivers/gpu/drm/ttm/ttm_resource.c +0 -16
-bool ttm_resource_compat(struct ttm_resource *res,
-             struct ttm_placement *placement)
-{
-    if (ttm_resource_places_compat(res, placement->placement,
-                       placement->num_placement))
-        return true;
-
-    if ((placement->busy_placement != placement->placement ||
-         placement->num_busy_placement > placement->num_placement) &&
-        ttm_resource_places_compat(res, placement->busy_placement,
-                       placement->num_busy_placement))
-        return true;
-
-    return false;
-}
-

  void ttm_resource_set_bo(struct ttm_resource *res, struct ttm_buffer_object *bo) {

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +10 -0
index 2bfac3aad7b7..bfd41ce3c8f4 100644
@@ -742,9 +742,21 @@ void vmw_bo_move_notify(struct ttm_buffer_object 
 *bo,
           vmw_resource_unbind_list(vbo);
   }
   +static u32 placement_flags(u32 domain, u32 desired, u32 fallback)
+{
+    if (desired & fallback & domain)
+        return 0;
+
+    if (desired & domain)
+        return TTM_PL_FLAG_DESIRED;
+
+    return TTM_PL_FLAG_FALLBACK;
+}
+

  static u32

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +1 -1
-set_placement_list(struct ttm_place *pl, u32 domain)
+set_placement_list(struct ttm_place *pl, u32 desired, u32 fallback)

  {
+    u32 domain = desired | fallback;
      u32 n = 0;
        /*

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +10 -5
@@ -752,35 +764,40 @@ set_placement_list(struct ttm_place *pl, u32 
 domain)
        */
       if (domain & VMW_BO_DOMAIN_MOB) {
           pl[n].mem_type = VMW_PL_MOB;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_MOB, desired,
+                          fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;
           n++;
       }
       if (domain & VMW_BO_DOMAIN_GMR) {
           pl[n].mem_type = VMW_PL_GMR;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_GMR, desired,
+                          fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;
           n++;
       }
       if (domain & VMW_BO_DOMAIN_VRAM) {
           pl[n].mem_type = TTM_PL_VRAM;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_VRAM, desired,
+                          fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;
           n++;
       }
       if (domain & VMW_BO_DOMAIN_WAITABLE_SYS) {
           pl[n].mem_type = VMW_PL_SYSTEM;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_WAITABLE_SYS,
+                          desired, fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;
           n++;
       }
       if (domain & VMW_BO_DOMAIN_SYS) {
           pl[n].mem_type = TTM_PL_SYSTEM;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_SYS, desired,
+                          fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;

          n++;

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +1 -2
@@ -806,7 +823,7 @@ void vmw_bo_placement_set(struct vmw_bo *bo, u32 
 domain, u32 busy_domain)
       u32 i;
         pl->placement = bo->places;
-    pl->num_placement = set_placement_list(bo->places, domain);
+    pl->num_placement = set_placement_list(bo->places, domain, 
 busy_domain);
         if (drm_debug_enabled(DRM_UT_DRIVER) && bo->tbo.resource) {
           for (i = 0; i < pl->num_placement; ++i) {
@@ -821,8 +838,6 @@ void vmw_bo_placement_set(struct vmw_bo *bo, u32 
 domain, u32 busy_domain)
                    __func__, bo->tbo.resource->mem_type, domain);
       }
   -    pl->busy_placement = bo->busy_places;
-    pl->num_busy_placement = set_placement_list(bo->busy_places, 
 busy_domain);
   }

    void vmw_bo_placement_set_default_accelerated(struct vmw_bo *bo)

drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +0 -4
index a84fffcef8e1..4d23d0a70bcb 100644
@@ -46,15 +46,11 @@ static const struct ttm_place sys_placement_flags 
 = {
   struct ttm_placement vmw_vram_placement = {
       .num_placement = 1,
       .placement = &vram_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &vram_placement_flags
   };
     struct ttm_placement vmw_sys_placement = {
       .num_placement = 1,
       .placement = &sys_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &sys_placement_flags
   };
     const size_t vmw_tt_size = sizeof(struct vmw_ttm_tt);
drivers/gpu/drm/xe/xe_bo.c +15 -13
index 8e4a3b1f6b93..1e5edc7f0b85 100644
@@ -38,22 +38,26 @@ static const struct ttm_place sys_placement_flags 
 = {
   static struct ttm_placement sys_placement = {
       .num_placement = 1,
       .placement = &sys_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &sys_placement_flags,
   };
   -static const struct ttm_place tt_placement_flags = {
-    .fpfn = 0,
-    .lpfn = 0,
-    .mem_type = XE_PL_TT,
-    .flags = 0,
+static const struct ttm_place tt_placement_flags[] = {
+    {
+        .fpfn = 0,
+        .lpfn = 0,
+        .mem_type = XE_PL_TT,
+        .flags = TTM_PL_FLAG_DESIRED,
+    },
+    {
+        .fpfn = 0,
+        .lpfn = 0,
+        .mem_type = XE_PL_SYSTEM,
+        .flags = TTM_PL_FLAG_FALLBACK,
+    }
   };
     static struct ttm_placement tt_placement = {
-    .num_placement = 1,
-    .placement = &tt_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &sys_placement_flags,
+    .num_placement = 2,
+    .placement = tt_placement_flags,
   };
     bool mem_type_is_vram(u32 mem_type)
@@ -230,8 +234,6 @@ static int __xe_bo_placement_for_flags(struct 
 xe_device *xe, struct xe_bo *bo,
       bo->placement = (struct ttm_placement) {
           .num_placement = c,
           .placement = bo->placements,
-        .num_busy_placement = c,
-        .busy_placement = bo->placements,
       };
         return 0;
@@ -251,7 +253,6 @@ static void xe_evict_flags(struct 
 ttm_buffer_object *tbo,
           /* Don't handle scatter gather BOs */
           if (tbo->type == ttm_bo_type_sg) {
               placement->num_placement = 0;
-            placement->num_busy_placement = 0;
               return;
           }

  @@ -1353,8 +1354,6 @@ static int __xe_bo_fixed_placement(struct xe_device *xe, bo->placement = (struct ttm_placement) {
          .num_placement = 1,
          .placement = place,
-        .num_busy_placement = 1,
-        .busy_placement = place,
      };
        return 0;

drivers/gpu/drm/xe/xe_bo.c +0 -2
@@ -2112,9 +2111,7 @@ int xe_bo_migrate(struct xe_bo *bo, u32 mem_type)
         xe_place_from_ttm_type(mem_type, &requested);
       placement.num_placement = 1;
-    placement.num_busy_placement = 1;
       placement.placement = &requested;
-    placement.busy_placement = &requested;
         /*
        * Stolen needs to be handled like below VRAM handling if we ever need
include/drm/ttm/ttm_placement.h +0 -0
index 8074d0f6cae5..b510a4812609 100644
@@ -64,6 +64,12 @@
   /* For multihop handling */
   #define TTM_PL_FLAG_TEMPORARY   (1 << 2)

  +/* Placement is never used during eviction */

include/drm/ttm/ttm_placement.h +5 -0
+#define TTM_PL_FLAG_DESIRED    (1 << 3)
+
+/* Placement is only used during eviction */
+#define TTM_PL_FLAG_FALLBACK    (1 << 4)
+

  /**
   * struct ttm_place
   *

include/drm/ttm/ttm_placement.h +0 -1
@@ -86,16 +92,12 @@ struct ttm_place {
    *
    * @num_placement:    number of preferred placements
    * @placement:        preferred placements
- * @num_busy_placement:    number of preferred placements when need 

to evict buffer
- * @busy_placement:    preferred placements when need to evict buffer *
   * Structure indicating the placement you request for an object. */
  struct ttm_placement {
      unsigned        num_placement;
      const struct ttm_place    *placement;
-    unsigned        num_busy_placement;
-    const struct ttm_place    *busy_placement;
  };
    #endif

include/drm/ttm/ttm_resource.h +2 -6
index 78a226eba953..1afa13f0c22b 100644
@@ -365,12 +365,8 @@ bool ttm_resource_intersects(struct ttm_device 
 *bdev,
                    struct ttm_resource *res,
                    const struct ttm_place *place,
                    size_t size);
-bool ttm_resource_compatible(struct ttm_device *bdev,
-                 struct ttm_resource *res,
-                 const struct ttm_place *place,
-                 size_t size);
-bool ttm_resource_compat(struct ttm_resource *res,
-             struct ttm_placement *placement);
+bool ttm_resource_compatible(struct ttm_resource *res,
+                 struct ttm_placement *placement);
   void ttm_resource_set_bo(struct ttm_resource *res,
                struct ttm_buffer_object *bo);
maintainer Reviewed-by
#8 lore raw

Re: [PATCH 3/5] drm/ttm: replace busy placement with flags v6

Quoted 7 lines · Thomas Hellström
Quoted 3 lines · Thomas Hellström

Hi, Christian

Xe changes look good. Will send the series to xe ci to check for regressions.

Hmm, there are some checkpatch warnings about author / SOB email mismatch,

With those fixed, this patch is

Quoted 6 lines

But worserthere are some regressions in the dma-buf ktest (it tests evicting of a dynamic dma-buf),

https://patchwork.freedesktop.org/series/128873/

I'll take a look later today or tomorrow.

These are from the next patch. Will continue the discussion there.

/Thomas

Quoted 863 lines

/Thomas

Quoted 858 lines

/Thomas

Quoted 853 lines · Christian König

From: Somalapuram Amaranath <[email protected]>

Instead of a list of separate busy placement add flags which indicate that a placement should only be used when there is room or if we need to evict.

v2: add missing TTM_PL_FLAG_IDLE for i915
v3: fix auto build test ERROR on drm-tip/drm-tip
v4: fix some typos pointed out by checkpatch
v5: cleanup some rebase problems with VMWGFX
v6: implement some missing VMWGFX functionality pointed out by Zack, rename the flags as suggested by Michel, rebase on drm-tip and adjust XE as well

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |  6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 11 +--- drivers/gpu/drm/drm_gem_vram_helper.c      |  2 - drivers/gpu/drm/i915/gem/i915_gem_ttm.c    | 37 +++++------ drivers/gpu/drm/loongson/lsdc_ttm.c        |  2 - drivers/gpu/drm/nouveau/nouveau_bo.c       | 59 +++++++---------- drivers/gpu/drm/nouveau/nouveau_bo.h       |  1 - drivers/gpu/drm/qxl/qxl_object.c           |  2 - drivers/gpu/drm/qxl/qxl_ttm.c              |  2 - drivers/gpu/drm/radeon/radeon_object.c     |  2 - drivers/gpu/drm/radeon/radeon_ttm.c        |  8 +-- drivers/gpu/drm/radeon/radeon_uvd.c        |  1 - drivers/gpu/drm/ttm/ttm_bo.c               | 21 ++++--- drivers/gpu/drm/ttm/ttm_resource.c         | 73
+++++-----------------
  drivers/gpu/drm/vmwgfx/vmwgfx_bo.c         | 33 +++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c |  4 -- drivers/gpu/drm/xe/xe_bo.c                 | 33 +++++----- include/drm/ttm/ttm_placement.h            | 10 +-- include/drm/ttm/ttm_resource.h             |  8 +--

  19 files changed, 118 insertions(+), 197 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -5
index 425cebcc5cbf..b671b0665492 100644
@@ -220,9 +220,6 @@ void amdgpu_bo_placement_from_domain(struct 
 amdgpu_bo *abo, u32 domain)
         placement->num_placement = c;
       placement->placement = places;
-
-    placement->num_busy_placement = c;
-    placement->busy_placement = places;
   }
     /**
@@ -1397,8 +1394,7 @@ vm_fault_t 
 amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
                       AMDGPU_GEM_DOMAIN_GTT);
         /* Avoid costly evictions; only set GTT as a busy placement */
-    abo->placement.num_busy_placement = 1;
-    abo->placement.busy_placement = &abo->placements[1];
+    abo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
         r = ttm_bo_validate(bo, &abo->placement, &ctx);
       if (unlikely(r == -EBUSY || r == -ERESTARTSYS))
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -4
index 75c9fd2c6c2a..8722beba494e 100644
@@ -102,23 +102,19 @@ static void amdgpu_evict_flags(struct 
 ttm_buffer_object *bo,
       /* Don't handle scatter gather BOs */
       if (bo->type == ttm_bo_type_sg) {
           placement->num_placement = 0;
-        placement->num_busy_placement = 0;
           return;
       }
         /* Object isn't an AMDGPU object so ignore */
       if (!amdgpu_bo_is_amdgpu_bo(bo)) {
           placement->placement = &placements;
-        placement->busy_placement = &placements;
           placement->num_placement = 1;
-        placement->num_busy_placement = 1;
           return;
       }
         abo = ttm_to_amdgpu_bo(bo);
       if (abo->flags & AMDGPU_GEM_CREATE_DISCARDABLE) {
           placement->num_placement = 0;
-        placement->num_busy_placement = 0;
           return;
       }
   @@ -128,13 +124,13 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,

      case AMDGPU_PL_OA:
      case AMDGPU_PL_DOORBELL:
          placement->num_placement = 0;
-        placement->num_busy_placement = 0;
          return;
        case TTM_PL_VRAM:
          if (!adev->mman.buffer_funcs_enabled) {
              /* Move to system memory */ amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_CPU); +
          } else if (!amdgpu_gmc_vram_full_visible(&adev->gmc) && !(abo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) && amdgpu_bo_in_cpu_visible_vram(abo)) {

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
@@ -149,8 +145,7 @@ static void amdgpu_evict_flags(struct 
 ttm_buffer_object *bo,
                               AMDGPU_GEM_DOMAIN_CPU);

              abo->placements[0].fpfn = adev->gmc.visible_vram_size

Quoted 1 line
Quoted 1 line

PAGE_SHIFT;

              abo->placements[0].lpfn = 0;
-            abo->placement.busy_placement = &abo->placements[1]; -            abo->placement.num_busy_placement = 1;
+            abo->placements[0].flags |= TTM_PL_FLAG_DESIRED; } else {
              /* Move to GTT memory */ amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT |

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -2
@@ -966,8 +961,6 @@ int amdgpu_ttm_alloc_gart(struct 
 ttm_buffer_object *bo)
       /* allocate GART space */
       placement.num_placement = 1;
       placement.placement = &placements;
-    placement.num_busy_placement = 1;
-    placement.busy_placement = &placements;
       placements.fpfn = 0;
       placements.lpfn = adev->gmc.gart_size >> PAGE_SHIFT;

      placements.mem_type = TTM_PL_TT;

drivers/gpu/drm/drm_gem_vram_helper.c +0 -2
index b67eafa55715..75f2eaf0d5b6 100644
@@ -147,7 +147,6 @@ static void drm_gem_vram_placement(struct 
 drm_gem_vram_object *gbo,
           invariant_flags = TTM_PL_FLAG_TOPDOWN;
         gbo->placement.placement = gbo->placements;
-    gbo->placement.busy_placement = gbo->placements;
         if (pl_flag & DRM_GEM_VRAM_PL_FLAG_VRAM) {
           gbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -160,7 +159,6 @@ static void drm_gem_vram_placement(struct 
 drm_gem_vram_object *gbo,
       }
         gbo->placement.num_placement = c;
-    gbo->placement.num_busy_placement = c;
         for (i = 0; i < c; ++i) {
           gbo->placements[i].fpfn = 0;
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -2
index 6b69ef0cdbb4..80c6cafc8887 100644
@@ -65,8 +65,6 @@ static const struct ttm_place sys_placement_flags = {
   static struct ttm_placement i915_sys_placement = {
       .num_placement = 1,
       .placement = &sys_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &sys_placement_flags,
   };
     /**
@@ -157,32 +155,28 @@ i915_ttm_place_from_region(const struct 
 intel_memory_region *mr,

    static void
  i915_ttm_placement_from_obj(const struct drm_i915_gem_object *obj, -                struct ttm_place *requested,
-                struct ttm_place *busy,
+                struct ttm_place *places,
                  struct ttm_placement *placement)
  {
      unsigned int num_allowed = obj->mm.n_placements; unsigned int flags = obj->flags;
      unsigned int i;
  -    placement->num_placement = 1;
+    places[0].flags |= TTM_PL_FLAG_DESIRED; i915_ttm_place_from_region(num_allowed ? obj->mm.placements[0] :
-                   obj->mm.region, requested, obj->bo_offset, +                   obj->mm.region, &places[0], obj->bo_offset, obj->base.size, flags);
        /* Cache this on object? */
-    placement->num_busy_placement = num_allowed;
-    for (i = 0; i < placement->num_busy_placement; ++i)
-        i915_ttm_place_from_region(obj->mm.placements[i], busy + i, -                       obj->bo_offset, obj->base.size, flags); -
-    if (num_allowed == 0) {
-        *busy = *requested;
-        placement->num_busy_placement = 1;
+    for (i = 0; i < num_allowed; ++i) {
+        i915_ttm_place_from_region(obj->mm.placements[i], +                       &places[i + 1], obj->bo_offset,
+                       obj->base.size, flags);
+        places[i + 1].flags |= TTM_PL_FLAG_FALLBACK;
      }
  -    placement->placement = requested;
-    placement->busy_placement = busy;
+    placement->num_placement = num_allowed + 1;
+    placement->placement = places;
  }
    static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev,

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +3 -2
@@ -789,7 +783,8 @@ static int __i915_ttm_get_pages(struct 
 drm_i915_gem_object *obj,
       int ret;
         /* First try only the requested placement. No eviction. */
-    real_num_busy = fetch_and_zero(&placement->num_busy_placement);
+    real_num_busy = placement->num_placement;
+    placement->num_placement = 1;
       ret = ttm_bo_validate(bo, placement, &ctx);
       if (ret) {
           ret = i915_ttm_err_to_gem(ret);
@@ -805,7 +800,7 @@ static int __i915_ttm_get_pages(struct 
 drm_i915_gem_object *obj,
            * If the initial attempt fails, allow all accepted placements,
            * evicting if necessary.
            */
-        placement->num_busy_placement = real_num_busy;
+        placement->num_placement = real_num_busy;
           ret = ttm_bo_validate(bo, placement, &ctx);
           if (ret)

              return i915_ttm_err_to_gem(ret);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -4
@@ -839,7 +834,7 @@ static int __i915_ttm_get_pages(struct 
 drm_i915_gem_object *obj,
     static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
   {
-    struct ttm_place requested, busy[I915_TTM_MAX_PLACEMENTS];
+    struct ttm_place places[I915_TTM_MAX_PLACEMENTS + 1];
       struct ttm_placement placement;
         /* restricted by sg_alloc_table */
@@ -849,7 +844,7 @@ static int i915_ttm_get_pages(struct 
 drm_i915_gem_object *obj)
       GEM_BUG_ON(obj->mm.n_placements > I915_TTM_MAX_PLACEMENTS);
         /* Move to the requested placement. */
-    i915_ttm_placement_from_obj(obj, &requested, busy, &placement);
+    i915_ttm_placement_from_obj(obj, places, &placement);
         return __i915_ttm_get_pages(obj, &placement);
   }
@@ -879,9 +874,7 @@ static int __i915_ttm_migrate(struct 
 drm_i915_gem_object *obj,
       i915_ttm_place_from_region(mr, &requested, obj->bo_offset,
                      obj->base.size, flags);
       placement.num_placement = 1;
-    placement.num_busy_placement = 1;
       placement.placement = &requested;
-    placement.busy_placement = &requested;
         ret = __i915_ttm_get_pages(obj, &placement);
       if (ret)
drivers/gpu/drm/loongson/lsdc_ttm.c +0 -2
index bf79dc55afa4..465f622ac05d 100644
@@ -54,7 +54,6 @@ static void lsdc_bo_set_placement(struct lsdc_bo 
 *lbo, u32 domain)
           pflags |= TTM_PL_FLAG_TOPDOWN;
         lbo->placement.placement = lbo->placements;
-    lbo->placement.busy_placement = lbo->placements;
         if (domain & LSDC_GEM_DOMAIN_VRAM) {
           lbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -77,7 +76,6 @@ static void lsdc_bo_set_placement(struct lsdc_bo 
 *lbo, u32 domain)
       }
         lbo->placement.num_placement = c;
-    lbo->placement.num_busy_placement = c;
         for (i = 0; i < c; ++i) {
           lbo->placements[i].fpfn = 0;
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -0
index 00cc7d1abaa3..56dcd25db1ce 100644
@@ -404,27 +404,6 @@ nouveau_bo_new(struct nouveau_cli *cli, u64 
 size, int align,
       return 0;
   }

  -static void

drivers/gpu/drm/nouveau/nouveau_bo.c +0 -20
-set_placement_list(struct ttm_place *pl, unsigned *n, uint32_t domain)
-{
-    *n = 0;
-
-    if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
-        pl[*n].mem_type = TTM_PL_VRAM;
-        pl[*n].flags = 0;
-        (*n)++;
-    }
-    if (domain & NOUVEAU_GEM_DOMAIN_GART) {
-        pl[*n].mem_type = TTM_PL_TT;
-        pl[*n].flags = 0;
-        (*n)++;
-    }
-    if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
-        pl[*n].mem_type = TTM_PL_SYSTEM;
-        pl[(*n)++].flags = 0;
-    }
-}
-

  static void
  set_placement_range(struct nouveau_bo *nvbo, uint32_t domain) {

drivers/gpu/drm/nouveau/nouveau_bo.c +0 -4
@@ -452,10 +431,6 @@ set_placement_range(struct nouveau_bo *nvbo, 
 uint32_t domain)
               nvbo->placements[i].fpfn = fpfn;
               nvbo->placements[i].lpfn = lpfn;
           }
-        for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-            nvbo->busy_placements[i].fpfn = fpfn;
-            nvbo->busy_placements[i].lpfn = lpfn;
-        }
       }
   }

  @@ -463,15 +438,32 @@ void
  nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t domain,
               uint32_t busy)
  {
-    struct ttm_placement *pl = &nvbo->placement;
+    unsigned int *n = &nvbo->placement.num_placement;
+    struct ttm_place *pl = nvbo->placements;
  -    pl->placement = nvbo->placements;
-    set_placement_list(nvbo->placements, &pl->num_placement, domain);
+    domain |= busy;
  -    pl->busy_placement = nvbo->busy_placements;
-    set_placement_list(nvbo->busy_placements, &pl->num_busy_placement,
-               domain | busy);
+    *n = 0;
+    if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
+        pl[*n].mem_type = TTM_PL_VRAM;
+        pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_VRAM ?
+            TTM_PL_FLAG_FALLBACK : 0;
+        (*n)++;
+    }
+    if (domain & NOUVEAU_GEM_DOMAIN_GART) {
+        pl[*n].mem_type = TTM_PL_TT;
+        pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_GART ?
+            TTM_PL_FLAG_FALLBACK : 0;
+        (*n)++;
+    }
+    if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
+        pl[*n].mem_type = TTM_PL_SYSTEM;
+        pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_CPU ?
+            TTM_PL_FLAG_FALLBACK : 0;
+        (*n)++;
+    }
  +    nvbo->placement.placement = nvbo->placements;
      set_placement_range(nvbo, domain);
  }
  @@ -1314,11 +1306,6 @@ vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo) nvbo->placements[i].lpfn = mappable;
          }
  -        for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-            nvbo->busy_placements[i].fpfn = 0;
-            nvbo->busy_placements[i].lpfn = mappable;
-        }
-
          nouveau_bo_placement_set(nvbo, NOUVEAU_GEM_DOMAIN_VRAM, 0);
      }
  diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.h b/drivers/gpu/drm/nouveau/nouveau_bo.h index 70c551921a9e..e9dfab6a8156 100644

drivers/gpu/drm/nouveau/nouveau_bo.h +0 -1
@@ -15,7 +15,6 @@ struct nouveau_bo {
       struct ttm_placement placement;
       u32 valid_domains;
       struct ttm_place placements[3];
-    struct ttm_place busy_placements[3];
       bool force_coherent;
       struct ttm_bo_kmap_obj kmap;
       struct list_head head;
drivers/gpu/drm/qxl/qxl_object.c +0 -2
index 06a58dad5f5c..1e46b0a6e478 100644
@@ -66,7 +66,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo 
 *qbo, u32 domain)
           pflag |= TTM_PL_FLAG_TOPDOWN;
         qbo->placement.placement = qbo->placements;
-    qbo->placement.busy_placement = qbo->placements;
       if (domain == QXL_GEM_DOMAIN_VRAM) {
           qbo->placements[c].mem_type = TTM_PL_VRAM;
           qbo->placements[c++].flags = pflag;
@@ -86,7 +85,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo 
 *qbo, u32 domain)
           qbo->placements[c++].flags = 0;
       }
       qbo->placement.num_placement = c;
-    qbo->placement.num_busy_placement = c;
       for (i = 0; i < c; ++i) {
           qbo->placements[i].fpfn = 0;

          qbo->placements[i].lpfn = 0;

drivers/gpu/drm/qxl/qxl_ttm.c +0 -2
index 1a82629bce3f..765a144cea14 100644
@@ -60,9 +60,7 @@ static void qxl_evict_flags(struct 
 ttm_buffer_object *bo,
         if (!qxl_ttm_bo_is_qxl_bo(bo)) {
           placement->placement = &placements;
-        placement->busy_placement = &placements;
           placement->num_placement = 1;
-        placement->num_busy_placement = 1;
           return;
       }
       qbo = to_qxl_bo(bo);
drivers/gpu/drm/radeon/radeon_object.c +0 -2
index 10c0fbd9d2b4..a955f8a2f7fe 100644
@@ -78,7 +78,6 @@ void radeon_ttm_placement_from_domain(struct 
 radeon_bo *rbo, u32 domain)
       u32 c = 0, i;
         rbo->placement.placement = rbo->placements;
-    rbo->placement.busy_placement = rbo->placements;
       if (domain & RADEON_GEM_DOMAIN_VRAM) {
           /* Try placing BOs which don't need CPU access outside of the
            * CPU accessible part of VRAM
@@ -114,7 +113,6 @@ void radeon_ttm_placement_from_domain(struct 
 radeon_bo *rbo, u32 domain)
       }
         rbo->placement.num_placement = c;
-    rbo->placement.num_busy_placement = c;
         for (i = 0; i < c; ++i) {

          if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&

drivers/gpu/drm/radeon/radeon_ttm.c +0 -2
index de4e6d78f1e1..2078b0000e22 100644
@@ -92,9 +92,7 @@ static void radeon_evict_flags(struct 
 ttm_buffer_object *bo,
         if (!radeon_ttm_bo_is_radeon_bo(bo)) {
           placement->placement = &placements;
-        placement->busy_placement = &placements;
           placement->num_placement = 1;
-        placement->num_busy_placement = 1;
           return;
       }
       rbo = container_of(bo, struct radeon_bo, tbo);
@@ -114,15 +112,11 @@ static void radeon_evict_flags(struct 
 ttm_buffer_object *bo,
                */

              radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_VRAM | RADEON_GEM_DOMAIN_GTT);
-            rbo->placement.num_busy_placement = 0;
              for (i = 0; i < rbo->placement.num_placement; i++) { if (rbo->placements[i].mem_type == TTM_PL_VRAM) { if (rbo->placements[i].fpfn < fpfn) rbo->placements[i].fpfn = fpfn;
-                } else {
-                    rbo->placement.busy_placement =
-                        &rbo->placements[i];
-                    rbo->placement.num_busy_placement = 1;
+                    rbo->placements[0].flags |= TTM_PL_FLAG_DESIRED; }
              }
          } else

drivers/gpu/drm/radeon/radeon_uvd.c +0 -1
index a2cda184b2b2..058a1c8451b2 100644
@@ -324,7 +324,6 @@ void radeon_uvd_force_into_uvd_segment(struct 
 radeon_bo *rbo,
       rbo->placements[1].fpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
       rbo->placements[1].lpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
       rbo->placement.num_placement++;
-    rbo->placement.num_busy_placement++;
   }
     void radeon_uvd_free_handles(struct radeon_device *rdev, struct drm_file *filp)
drivers/gpu/drm/ttm/ttm_bo.c +11 -5
index 8c1eaa74fa21..a5e11a92e0b9 100644
@@ -410,8 +410,8 @@ static int ttm_bo_bounce_temp_buffer(struct 
 ttm_buffer_object *bo,
       struct ttm_resource *hop_mem;
       int ret;
   -    hop_placement.num_placement = hop_placement.num_busy_placement = 1;
-    hop_placement.placement = hop_placement.busy_placement = hop;
+    hop_placement.num_placement = 1;
+    hop_placement.placement = hop;
         /* find space in the bounce domain */
       ret = ttm_bo_mem_space(bo, &hop_placement, &hop_mem, ctx);
@@ -440,10 +440,9 @@ static int ttm_bo_evict(struct 
 ttm_buffer_object *bo,
       dma_resv_assert_held(bo->base.resv);
         placement.num_placement = 0;
-    placement.num_busy_placement = 0;
       bdev->funcs->evict_flags(bo, &placement);
   -    if (!placement.num_placement && !placement.num_busy_placement) {
+    if (!placement.num_placement) {
           ret = ttm_bo_wait_ctx(bo, ctx);
           if (ret)
               return ret;
@@ -791,6 +790,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
           const struct ttm_place *place = &placement->placement[i];
           struct ttm_resource_manager *man;
   +        if (place->flags & TTM_PL_FLAG_FALLBACK)
+            continue;
+
           man = ttm_manager_type(bdev, place->mem_type);
           if (!man || !ttm_resource_manager_used(man))
               continue;
@@ -813,10 +815,13 @@ int ttm_bo_mem_space(struct ttm_buffer_object 
 *bo,
           return 0;
       }
   -    for (i = 0; i < placement->num_busy_placement; ++i) {
-        const struct ttm_place *place = &placement->busy_placement[i];
+    for (i = 0; i < placement->num_placement; ++i) {
+        const struct ttm_place *place = &placement->placement[i];
           struct ttm_resource_manager *man;
   +        if (place->flags & TTM_PL_FLAG_DESIRED)
+            continue;
+
           man = ttm_manager_type(bdev, place->mem_type);
           if (!man || !ttm_resource_manager_used(man))
               continue;
@@ -904,11 +909,11 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
       /*
        * Remove the backing store if no placement is given.
        */
-    if (!placement->num_placement && !placement->num_busy_placement)
+    if (!placement->num_placement)
           return ttm_bo_pipeline_gutting(bo);
         /* Check whether we need to move buffer. */
-    if (bo->resource && ttm_resource_compat(bo->resource, placement))
+    if (bo->resource && ttm_resource_compatible(bo->resource, 
 placement))
           return 0;
         /* Moving of pinned BOs is forbidden */
drivers/gpu/drm/ttm/ttm_resource.c +1 -1
index 02b96d23fdb9..fb14f7716cf8 100644
@@ -291,37 +291,15 @@ bool ttm_resource_intersects(struct ttm_device 
 *bdev,
   }
     /**
- * ttm_resource_compatible - test for compatibility
+ * ttm_resource_compatible - check if resource is compatible with 

placement
   *
- * @bdev: TTM device structure
- * @res: The resource to test
- * @place: The placement to test
- * @size: How many bytes the new allocation needs.
- *
- * Test if @res compatible with @place and @size.
+ * @res: the resource to check
+ * @placement: the placement to check against
   *
- * Returns true if the res placement compatible with @place and @size.
+ * Returns true if the placement is compatible.
   */

drivers/gpu/drm/ttm/ttm_resource.c +2 -20
-bool ttm_resource_compatible(struct ttm_device *bdev,
-                 struct ttm_resource *res,
-                 const struct ttm_place *place,
-                 size_t size)
-{
-    struct ttm_resource_manager *man;
-
-    if (!res || !place)
-        return false;
-
-    man = ttm_manager_type(bdev, res->mem_type);
-    if (!man->func->compatible)
-        return true;
-
-    return man->func->compatible(man, res, place, size);
-}
-
-static bool ttm_resource_places_compat(struct ttm_resource *res,
-                       const struct ttm_place *places,
-                       unsigned num_placement)
+bool ttm_resource_compatible(struct ttm_resource *res,
+                 struct ttm_placement *placement)

  {
      struct ttm_buffer_object *bo = res->bo;
      struct ttm_device *bdev = bo->bdev;

drivers/gpu/drm/ttm/ttm_resource.c +9 -1
@@ -330,44 +308,25 @@ static bool ttm_resource_places_compat(struct 
 ttm_resource *res,
       if (res->placement & TTM_PL_FLAG_TEMPORARY)
           return false;
   -    for (i = 0; i < num_placement; i++) {
-        const struct ttm_place *heap = &places[i];
+    for (i = 0; i < placement->num_placement; i++) {
+        const struct ttm_place *place = &placement->placement[i];
+        struct ttm_resource_manager *man;
   -        if (!ttm_resource_compatible(bdev, res, heap, bo->base.size))
+        if (res->mem_type != place->mem_type)
+            continue;
+
+        man = ttm_manager_type(bdev, res->mem_type);
+        if (man->func->compatible &&
+            !man->func->compatible(man, res, place, bo->base.size))
               continue;

  -        if ((res->mem_type == heap->mem_type) && -            (!(heap->flags & TTM_PL_FLAG_CONTIGUOUS) || +        if ((!(place->flags & TTM_PL_FLAG_CONTIGUOUS) || (res->placement & TTM_PL_FLAG_CONTIGUOUS))) return true;
      }
      return false;
  }
  -/**
- * ttm_resource_compat - check if resource is compatible with placement
- *
- * @res: the resource to check
- * @placement: the placement to check against
- *
- * Returns true if the placement is compatible.
- */

drivers/gpu/drm/ttm/ttm_resource.c +0 -16
-bool ttm_resource_compat(struct ttm_resource *res,
-             struct ttm_placement *placement)
-{
-    if (ttm_resource_places_compat(res, placement->placement,
-                       placement->num_placement))
-        return true;
-
-    if ((placement->busy_placement != placement->placement ||
-         placement->num_busy_placement > placement->num_placement) &&
-        ttm_resource_places_compat(res, placement->busy_placement,
-                       placement->num_busy_placement))
-        return true;
-
-    return false;
-}
-

  void ttm_resource_set_bo(struct ttm_resource *res, struct ttm_buffer_object *bo) {

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +10 -0
index 2bfac3aad7b7..bfd41ce3c8f4 100644
@@ -742,9 +742,21 @@ void vmw_bo_move_notify(struct 
 ttm_buffer_object *bo,
           vmw_resource_unbind_list(vbo);
   }
   +static u32 placement_flags(u32 domain, u32 desired, u32 fallback)
+{
+    if (desired & fallback & domain)
+        return 0;
+
+    if (desired & domain)
+        return TTM_PL_FLAG_DESIRED;
+
+    return TTM_PL_FLAG_FALLBACK;
+}
+

  static u32

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +1 -1
-set_placement_list(struct ttm_place *pl, u32 domain)
+set_placement_list(struct ttm_place *pl, u32 desired, u32 fallback)

  {
+    u32 domain = desired | fallback;
      u32 n = 0;
        /*

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +10 -5
@@ -752,35 +764,40 @@ set_placement_list(struct ttm_place *pl, u32 
 domain)
        */
       if (domain & VMW_BO_DOMAIN_MOB) {
           pl[n].mem_type = VMW_PL_MOB;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_MOB, desired,
+                          fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;
           n++;
       }
       if (domain & VMW_BO_DOMAIN_GMR) {
           pl[n].mem_type = VMW_PL_GMR;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_GMR, desired,
+                          fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;
           n++;
       }
       if (domain & VMW_BO_DOMAIN_VRAM) {
           pl[n].mem_type = TTM_PL_VRAM;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_VRAM, desired,
+                          fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;
           n++;
       }
       if (domain & VMW_BO_DOMAIN_WAITABLE_SYS) {
           pl[n].mem_type = VMW_PL_SYSTEM;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_WAITABLE_SYS,
+                          desired, fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;
           n++;
       }
       if (domain & VMW_BO_DOMAIN_SYS) {
           pl[n].mem_type = TTM_PL_SYSTEM;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_SYS, desired,
+                          fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;

          n++;

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +1 -2
@@ -806,7 +823,7 @@ void vmw_bo_placement_set(struct vmw_bo *bo, u32 
 domain, u32 busy_domain)
       u32 i;
         pl->placement = bo->places;
-    pl->num_placement = set_placement_list(bo->places, domain);
+    pl->num_placement = set_placement_list(bo->places, domain, 
 busy_domain);
         if (drm_debug_enabled(DRM_UT_DRIVER) && bo->tbo.resource) {
           for (i = 0; i < pl->num_placement; ++i) {
@@ -821,8 +838,6 @@ void vmw_bo_placement_set(struct vmw_bo *bo, u32 
 domain, u32 busy_domain)
                    __func__, bo->tbo.resource->mem_type, domain);
       }
   -    pl->busy_placement = bo->busy_places;
-    pl->num_busy_placement = set_placement_list(bo->busy_places, 
 busy_domain);
   }

    void vmw_bo_placement_set_default_accelerated(struct vmw_bo *bo)

drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +0 -4
index a84fffcef8e1..4d23d0a70bcb 100644
@@ -46,15 +46,11 @@ static const struct ttm_place 
 sys_placement_flags = {
   struct ttm_placement vmw_vram_placement = {
       .num_placement = 1,
       .placement = &vram_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &vram_placement_flags
   };
     struct ttm_placement vmw_sys_placement = {
       .num_placement = 1,
       .placement = &sys_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &sys_placement_flags
   };
     const size_t vmw_tt_size = sizeof(struct vmw_ttm_tt);
drivers/gpu/drm/xe/xe_bo.c +15 -13
index 8e4a3b1f6b93..1e5edc7f0b85 100644
@@ -38,22 +38,26 @@ static const struct ttm_place 
 sys_placement_flags = {
   static struct ttm_placement sys_placement = {
       .num_placement = 1,
       .placement = &sys_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &sys_placement_flags,
   };
   -static const struct ttm_place tt_placement_flags = {
-    .fpfn = 0,
-    .lpfn = 0,
-    .mem_type = XE_PL_TT,
-    .flags = 0,
+static const struct ttm_place tt_placement_flags[] = {
+    {
+        .fpfn = 0,
+        .lpfn = 0,
+        .mem_type = XE_PL_TT,
+        .flags = TTM_PL_FLAG_DESIRED,
+    },
+    {
+        .fpfn = 0,
+        .lpfn = 0,
+        .mem_type = XE_PL_SYSTEM,
+        .flags = TTM_PL_FLAG_FALLBACK,
+    }
   };
     static struct ttm_placement tt_placement = {
-    .num_placement = 1,
-    .placement = &tt_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &sys_placement_flags,
+    .num_placement = 2,
+    .placement = tt_placement_flags,
   };
     bool mem_type_is_vram(u32 mem_type)
@@ -230,8 +234,6 @@ static int __xe_bo_placement_for_flags(struct 
 xe_device *xe, struct xe_bo *bo,
       bo->placement = (struct ttm_placement) {
           .num_placement = c,
           .placement = bo->placements,
-        .num_busy_placement = c,
-        .busy_placement = bo->placements,
       };
         return 0;
@@ -251,7 +253,6 @@ static void xe_evict_flags(struct 
 ttm_buffer_object *tbo,
           /* Don't handle scatter gather BOs */
           if (tbo->type == ttm_bo_type_sg) {
               placement->num_placement = 0;
-            placement->num_busy_placement = 0;
               return;
           }

  @@ -1353,8 +1354,6 @@ static int __xe_bo_fixed_placement(struct xe_device *xe, bo->placement = (struct ttm_placement) {
          .num_placement = 1,
          .placement = place,
-        .num_busy_placement = 1,
-        .busy_placement = place,
      };
        return 0;

drivers/gpu/drm/xe/xe_bo.c +0 -2
@@ -2112,9 +2111,7 @@ int xe_bo_migrate(struct xe_bo *bo, u32 mem_type)
         xe_place_from_ttm_type(mem_type, &requested);
       placement.num_placement = 1;
-    placement.num_busy_placement = 1;
       placement.placement = &requested;
-    placement.busy_placement = &requested;
         /*
        * Stolen needs to be handled like below VRAM handling if we ever need
include/drm/ttm/ttm_placement.h +0 -0
index 8074d0f6cae5..b510a4812609 100644
@@ -64,6 +64,12 @@
   /* For multihop handling */
   #define TTM_PL_FLAG_TEMPORARY   (1 << 2)

  +/* Placement is never used during eviction */

include/drm/ttm/ttm_placement.h +5 -0
+#define TTM_PL_FLAG_DESIRED    (1 << 3)
+
+/* Placement is only used during eviction */
+#define TTM_PL_FLAG_FALLBACK    (1 << 4)
+

  /**
   * struct ttm_place
   *

include/drm/ttm/ttm_placement.h +0 -1
@@ -86,16 +92,12 @@ struct ttm_place {
    *
    * @num_placement:    number of preferred placements
    * @placement:        preferred placements
- * @num_busy_placement:    number of preferred placements when need 

to evict buffer
- * @busy_placement:    preferred placements when need to evict buffer *
   * Structure indicating the placement you request for an object. */
  struct ttm_placement {
      unsigned        num_placement;
      const struct ttm_place    *placement;
-    unsigned        num_busy_placement;
-    const struct ttm_place    *busy_placement;
  };
    #endif

include/drm/ttm/ttm_resource.h +2 -6
index 78a226eba953..1afa13f0c22b 100644
@@ -365,12 +365,8 @@ bool ttm_resource_intersects(struct ttm_device 
 *bdev,
                    struct ttm_resource *res,
                    const struct ttm_place *place,
                    size_t size);
-bool ttm_resource_compatible(struct ttm_device *bdev,
-                 struct ttm_resource *res,
-                 const struct ttm_place *place,
-                 size_t size);
-bool ttm_resource_compat(struct ttm_resource *res,
-             struct ttm_placement *placement);
+bool ttm_resource_compatible(struct ttm_resource *res,
+                 struct ttm_placement *placement);
   void ttm_resource_set_bo(struct ttm_resource *res,
                struct ttm_buffer_object *bo);
#9 lore raw

Re: Re: [PATCH 3/5] drm/ttm: replace busy placement with flags v6

Quoted 6 lines · Thomas Hellström
Quoted 4 lines · Thomas Hellström
Quoted 2 lines · Thomas Hellström

Hi, Christian

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Xe changes look good. Will send the series to xe ci to check for regressions.

Hmm, there are some checkpatch warnings about author / SOB email mismatch,

With those fixed, this patch is

it actually broke drm-tip now that this is merged:

../drivers/gpu/drm/xe/xe_bo.c:41:10: error: ‘struct ttm_placement’ has no member named ‘num_busy_placement’; did you mean ‘num_placement’

   41 |         .num_busy_placement = 1,
      |          ^~~~~~~~~~~~~~~~~~
      |          num_placement

../drivers/gpu/drm/xe/xe_bo.c:41:31: error: excess elements in struct initializer [-Werror]
41 | .num_busy_placement = 1,
| ^

Apparently a conflict with another patch that got applied a few days
ago: a201c6ee37d6 ("drm/xe/bo: Evict VRAM to TT rather than to system")

Lucas De Marchi

Quoted 876 lines
Quoted 8 lines

But worserthere are some regressions in the dma-buf ktest (it tests evicting of a dynamic dma-buf),

https://patchwork.freedesktop.org/series/128873/

I'll take a look later today or tomorrow.

These are from the next patch. Will continue the discussion there.

/Thomas

Quoted 862 lines

/Thomas

Quoted 857 lines

/Thomas

Quoted 852 lines · Christian König

From: Somalapuram Amaranath <[email protected]>

Instead of a list of separate busy placement add flags which indicate that a placement should only be used when there is room or if we need to evict.

v2: add missing TTM_PL_FLAG_IDLE for i915
v3: fix auto build test ERROR on drm-tip/drm-tip
v4: fix some typos pointed out by checkpatch
v5: cleanup some rebase problems with VMWGFX
v6: implement some missing VMWGFX functionality pointed out by Zack, rename the flags as suggested by Michel, rebase on drm-tip and adjust XE as well

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |  6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 11 +--- drivers/gpu/drm/drm_gem_vram_helper.c      |  2 - drivers/gpu/drm/i915/gem/i915_gem_ttm.c    | 37 +++++------ drivers/gpu/drm/loongson/lsdc_ttm.c        |  2 - drivers/gpu/drm/nouveau/nouveau_bo.c       | 59 +++++++---------- drivers/gpu/drm/nouveau/nouveau_bo.h       |  1 - drivers/gpu/drm/qxl/qxl_object.c           |  2 - drivers/gpu/drm/qxl/qxl_ttm.c              |  2 - drivers/gpu/drm/radeon/radeon_object.c     |  2 - drivers/gpu/drm/radeon/radeon_ttm.c        |  8 +-- drivers/gpu/drm/radeon/radeon_uvd.c        |  1 - drivers/gpu/drm/ttm/ttm_bo.c               | 21 ++++--- drivers/gpu/drm/ttm/ttm_resource.c         | 73
+++++-----------------
  drivers/gpu/drm/vmwgfx/vmwgfx_bo.c         | 33 +++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c |  4 -- drivers/gpu/drm/xe/xe_bo.c                 | 33 +++++----- include/drm/ttm/ttm_placement.h            | 10 +-- include/drm/ttm/ttm_resource.h             |  8 +--

  19 files changed, 118 insertions(+), 197 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -5
index 425cebcc5cbf..b671b0665492 100644
@@ -220,9 +220,6 @@ void amdgpu_bo_placement_from_domain(struct 
 amdgpu_bo *abo, u32 domain)
         placement->num_placement = c;
       placement->placement = places;
-
-    placement->num_busy_placement = c;
-    placement->busy_placement = places;
   }
     /**
@@ -1397,8 +1394,7 @@ vm_fault_t 
 amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
                       AMDGPU_GEM_DOMAIN_GTT);
         /* Avoid costly evictions; only set GTT as a busy placement */
-    abo->placement.num_busy_placement = 1;
-    abo->placement.busy_placement = &abo->placements[1];
+    abo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
         r = ttm_bo_validate(bo, &abo->placement, &ctx);
       if (unlikely(r == -EBUSY || r == -ERESTARTSYS))
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -4
index 75c9fd2c6c2a..8722beba494e 100644
@@ -102,23 +102,19 @@ static void amdgpu_evict_flags(struct 
 ttm_buffer_object *bo,
       /* Don't handle scatter gather BOs */
       if (bo->type == ttm_bo_type_sg) {
           placement->num_placement = 0;
-        placement->num_busy_placement = 0;
           return;
       }
         /* Object isn't an AMDGPU object so ignore */
       if (!amdgpu_bo_is_amdgpu_bo(bo)) {
           placement->placement = &placements;
-        placement->busy_placement = &placements;
           placement->num_placement = 1;
-        placement->num_busy_placement = 1;
           return;
       }
         abo = ttm_to_amdgpu_bo(bo);
       if (abo->flags & AMDGPU_GEM_CREATE_DISCARDABLE) {
           placement->num_placement = 0;
-        placement->num_busy_placement = 0;
           return;
       }
   @@ -128,13 +124,13 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,

      case AMDGPU_PL_OA:
      case AMDGPU_PL_DOORBELL:
          placement->num_placement = 0;
-        placement->num_busy_placement = 0;
          return;
        case TTM_PL_VRAM:
          if (!adev->mman.buffer_funcs_enabled) {
              /* Move to system memory */ amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_CPU); +
          } else if (!amdgpu_gmc_vram_full_visible(&adev->gmc) && !(abo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) && amdgpu_bo_in_cpu_visible_vram(abo)) {

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -2
@@ -149,8 +145,7 @@ static void amdgpu_evict_flags(struct 
 ttm_buffer_object *bo,
                               AMDGPU_GEM_DOMAIN_CPU);
               abo->placements[0].fpfn = adev->gmc.visible_vram_size >> PAGE_SHIFT;
               abo->placements[0].lpfn = 0;
-            abo->placement.busy_placement = &abo->placements[1];
-            abo->placement.num_busy_placement = 1;
+            abo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
           } else {
               /* Move to GTT memory */

              amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT |

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -2
@@ -966,8 +961,6 @@ int amdgpu_ttm_alloc_gart(struct 
 ttm_buffer_object *bo)
       /* allocate GART space */
       placement.num_placement = 1;
       placement.placement = &placements;
-    placement.num_busy_placement = 1;
-    placement.busy_placement = &placements;
       placements.fpfn = 0;
       placements.lpfn = adev->gmc.gart_size >> PAGE_SHIFT;

      placements.mem_type = TTM_PL_TT;

drivers/gpu/drm/drm_gem_vram_helper.c +0 -2
index b67eafa55715..75f2eaf0d5b6 100644
@@ -147,7 +147,6 @@ static void drm_gem_vram_placement(struct 
 drm_gem_vram_object *gbo,
           invariant_flags = TTM_PL_FLAG_TOPDOWN;
         gbo->placement.placement = gbo->placements;
-    gbo->placement.busy_placement = gbo->placements;
         if (pl_flag & DRM_GEM_VRAM_PL_FLAG_VRAM) {
           gbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -160,7 +159,6 @@ static void drm_gem_vram_placement(struct 
 drm_gem_vram_object *gbo,
       }
         gbo->placement.num_placement = c;
-    gbo->placement.num_busy_placement = c;
         for (i = 0; i < c; ++i) {
           gbo->placements[i].fpfn = 0;
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -2
index 6b69ef0cdbb4..80c6cafc8887 100644
@@ -65,8 +65,6 @@ static const struct ttm_place sys_placement_flags = {
   static struct ttm_placement i915_sys_placement = {
       .num_placement = 1,
       .placement = &sys_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &sys_placement_flags,
   };
     /**
@@ -157,32 +155,28 @@ i915_ttm_place_from_region(const struct 
 intel_memory_region *mr,

    static void
  i915_ttm_placement_from_obj(const struct drm_i915_gem_object *obj, -                struct ttm_place *requested,
-                struct ttm_place *busy,
+                struct ttm_place *places,
                  struct ttm_placement *placement)
  {
      unsigned int num_allowed = obj->mm.n_placements; unsigned int flags = obj->flags;
      unsigned int i;
  -    placement->num_placement = 1;
+    places[0].flags |= TTM_PL_FLAG_DESIRED; i915_ttm_place_from_region(num_allowed ? obj->mm.placements[0] :
-                   obj->mm.region, requested, obj->bo_offset, +                   obj->mm.region, &places[0], obj->bo_offset, obj->base.size, flags);
        /* Cache this on object? */
-    placement->num_busy_placement = num_allowed;
-    for (i = 0; i < placement->num_busy_placement; ++i)
-        i915_ttm_place_from_region(obj->mm.placements[i], busy + i, -                       obj->bo_offset, obj->base.size, flags); -
-    if (num_allowed == 0) {
-        *busy = *requested;
-        placement->num_busy_placement = 1;
+    for (i = 0; i < num_allowed; ++i) {
+        i915_ttm_place_from_region(obj->mm.placements[i], +                       &places[i + 1], obj->bo_offset,
+                       obj->base.size, flags);
+        places[i + 1].flags |= TTM_PL_FLAG_FALLBACK;
      }
  -    placement->placement = requested;
-    placement->busy_placement = busy;
+    placement->num_placement = num_allowed + 1;
+    placement->placement = places;
  }
    static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev,

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +3 -2
@@ -789,7 +783,8 @@ static int __i915_ttm_get_pages(struct 
 drm_i915_gem_object *obj,
       int ret;
         /* First try only the requested placement. No eviction. */
-    real_num_busy = fetch_and_zero(&placement->num_busy_placement);
+    real_num_busy = placement->num_placement;
+    placement->num_placement = 1;
       ret = ttm_bo_validate(bo, placement, &ctx);
       if (ret) {
           ret = i915_ttm_err_to_gem(ret);
@@ -805,7 +800,7 @@ static int __i915_ttm_get_pages(struct 
 drm_i915_gem_object *obj,
            * If the initial attempt fails, allow all accepted placements,
            * evicting if necessary.
            */
-        placement->num_busy_placement = real_num_busy;
+        placement->num_placement = real_num_busy;
           ret = ttm_bo_validate(bo, placement, &ctx);
           if (ret)

              return i915_ttm_err_to_gem(ret);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -4
@@ -839,7 +834,7 @@ static int __i915_ttm_get_pages(struct 
 drm_i915_gem_object *obj,
     static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
   {
-    struct ttm_place requested, busy[I915_TTM_MAX_PLACEMENTS];
+    struct ttm_place places[I915_TTM_MAX_PLACEMENTS + 1];
       struct ttm_placement placement;
         /* restricted by sg_alloc_table */
@@ -849,7 +844,7 @@ static int i915_ttm_get_pages(struct 
 drm_i915_gem_object *obj)
       GEM_BUG_ON(obj->mm.n_placements > I915_TTM_MAX_PLACEMENTS);
         /* Move to the requested placement. */
-    i915_ttm_placement_from_obj(obj, &requested, busy, &placement);
+    i915_ttm_placement_from_obj(obj, places, &placement);
         return __i915_ttm_get_pages(obj, &placement);
   }
@@ -879,9 +874,7 @@ static int __i915_ttm_migrate(struct 
 drm_i915_gem_object *obj,
       i915_ttm_place_from_region(mr, &requested, obj->bo_offset,
                      obj->base.size, flags);
       placement.num_placement = 1;
-    placement.num_busy_placement = 1;
       placement.placement = &requested;
-    placement.busy_placement = &requested;
         ret = __i915_ttm_get_pages(obj, &placement);
       if (ret)
drivers/gpu/drm/loongson/lsdc_ttm.c +0 -2
index bf79dc55afa4..465f622ac05d 100644
@@ -54,7 +54,6 @@ static void lsdc_bo_set_placement(struct 
 lsdc_bo *lbo, u32 domain)
           pflags |= TTM_PL_FLAG_TOPDOWN;
         lbo->placement.placement = lbo->placements;
-    lbo->placement.busy_placement = lbo->placements;
         if (domain & LSDC_GEM_DOMAIN_VRAM) {
           lbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -77,7 +76,6 @@ static void lsdc_bo_set_placement(struct 
 lsdc_bo *lbo, u32 domain)
       }
         lbo->placement.num_placement = c;
-    lbo->placement.num_busy_placement = c;
         for (i = 0; i < c; ++i) {
           lbo->placements[i].fpfn = 0;
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -0
index 00cc7d1abaa3..56dcd25db1ce 100644
@@ -404,27 +404,6 @@ nouveau_bo_new(struct nouveau_cli *cli, u64 
 size, int align,
       return 0;
   }

  -static void

drivers/gpu/drm/nouveau/nouveau_bo.c +0 -20
-set_placement_list(struct ttm_place *pl, unsigned *n, uint32_t domain)
-{
-    *n = 0;
-
-    if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
-        pl[*n].mem_type = TTM_PL_VRAM;
-        pl[*n].flags = 0;
-        (*n)++;
-    }
-    if (domain & NOUVEAU_GEM_DOMAIN_GART) {
-        pl[*n].mem_type = TTM_PL_TT;
-        pl[*n].flags = 0;
-        (*n)++;
-    }
-    if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
-        pl[*n].mem_type = TTM_PL_SYSTEM;
-        pl[(*n)++].flags = 0;
-    }
-}
-

  static void
  set_placement_range(struct nouveau_bo *nvbo, uint32_t domain) {

drivers/gpu/drm/nouveau/nouveau_bo.c +0 -4
@@ -452,10 +431,6 @@ set_placement_range(struct nouveau_bo 
 *nvbo, uint32_t domain)
               nvbo->placements[i].fpfn = fpfn;
               nvbo->placements[i].lpfn = lpfn;
           }
-        for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-            nvbo->busy_placements[i].fpfn = fpfn;
-            nvbo->busy_placements[i].lpfn = lpfn;
-        }
       }
   }

  @@ -463,15 +438,32 @@ void
  nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t domain,
               uint32_t busy)
  {
-    struct ttm_placement *pl = &nvbo->placement;
+    unsigned int *n = &nvbo->placement.num_placement;
+    struct ttm_place *pl = nvbo->placements;
  -    pl->placement = nvbo->placements;
-    set_placement_list(nvbo->placements, &pl->num_placement, domain);
+    domain |= busy;
  -    pl->busy_placement = nvbo->busy_placements;
-    set_placement_list(nvbo->busy_placements, &pl->num_busy_placement,
-               domain | busy);
+    *n = 0;
+    if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
+        pl[*n].mem_type = TTM_PL_VRAM;
+        pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_VRAM ?
+            TTM_PL_FLAG_FALLBACK : 0;
+        (*n)++;
+    }
+    if (domain & NOUVEAU_GEM_DOMAIN_GART) {
+        pl[*n].mem_type = TTM_PL_TT;
+        pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_GART ?
+            TTM_PL_FLAG_FALLBACK : 0;
+        (*n)++;
+    }
+    if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
+        pl[*n].mem_type = TTM_PL_SYSTEM;
+        pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_CPU ?
+            TTM_PL_FLAG_FALLBACK : 0;
+        (*n)++;
+    }
  +    nvbo->placement.placement = nvbo->placements;
      set_placement_range(nvbo, domain);
  }
  @@ -1314,11 +1306,6 @@ vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo) nvbo->placements[i].lpfn = mappable;
          }
  -        for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-            nvbo->busy_placements[i].fpfn = 0;
-            nvbo->busy_placements[i].lpfn = mappable;
-        }
-
          nouveau_bo_placement_set(nvbo, NOUVEAU_GEM_DOMAIN_VRAM, 0);
      }
  diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.h b/drivers/gpu/drm/nouveau/nouveau_bo.h index 70c551921a9e..e9dfab6a8156 100644

drivers/gpu/drm/nouveau/nouveau_bo.h +0 -1
@@ -15,7 +15,6 @@ struct nouveau_bo {
       struct ttm_placement placement;
       u32 valid_domains;
       struct ttm_place placements[3];
-    struct ttm_place busy_placements[3];
       bool force_coherent;
       struct ttm_bo_kmap_obj kmap;
       struct list_head head;
drivers/gpu/drm/qxl/qxl_object.c +0 -2
index 06a58dad5f5c..1e46b0a6e478 100644
@@ -66,7 +66,6 @@ void qxl_ttm_placement_from_domain(struct 
 qxl_bo *qbo, u32 domain)
           pflag |= TTM_PL_FLAG_TOPDOWN;
         qbo->placement.placement = qbo->placements;
-    qbo->placement.busy_placement = qbo->placements;
       if (domain == QXL_GEM_DOMAIN_VRAM) {
           qbo->placements[c].mem_type = TTM_PL_VRAM;
           qbo->placements[c++].flags = pflag;
@@ -86,7 +85,6 @@ void qxl_ttm_placement_from_domain(struct 
 qxl_bo *qbo, u32 domain)
           qbo->placements[c++].flags = 0;
       }
       qbo->placement.num_placement = c;
-    qbo->placement.num_busy_placement = c;
       for (i = 0; i < c; ++i) {
           qbo->placements[i].fpfn = 0;

          qbo->placements[i].lpfn = 0;

drivers/gpu/drm/qxl/qxl_ttm.c +0 -2
index 1a82629bce3f..765a144cea14 100644
@@ -60,9 +60,7 @@ static void qxl_evict_flags(struct 
 ttm_buffer_object *bo,
         if (!qxl_ttm_bo_is_qxl_bo(bo)) {
           placement->placement = &placements;
-        placement->busy_placement = &placements;
           placement->num_placement = 1;
-        placement->num_busy_placement = 1;
           return;
       }
       qbo = to_qxl_bo(bo);
drivers/gpu/drm/radeon/radeon_object.c +0 -2
index 10c0fbd9d2b4..a955f8a2f7fe 100644
@@ -78,7 +78,6 @@ void radeon_ttm_placement_from_domain(struct 
 radeon_bo *rbo, u32 domain)
       u32 c = 0, i;
         rbo->placement.placement = rbo->placements;
-    rbo->placement.busy_placement = rbo->placements;
       if (domain & RADEON_GEM_DOMAIN_VRAM) {
           /* Try placing BOs which don't need CPU access outside of the
            * CPU accessible part of VRAM
@@ -114,7 +113,6 @@ void radeon_ttm_placement_from_domain(struct 
 radeon_bo *rbo, u32 domain)
       }
         rbo->placement.num_placement = c;
-    rbo->placement.num_busy_placement = c;
         for (i = 0; i < c; ++i) {

          if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&

drivers/gpu/drm/radeon/radeon_ttm.c +0 -2
index de4e6d78f1e1..2078b0000e22 100644
@@ -92,9 +92,7 @@ static void radeon_evict_flags(struct 
 ttm_buffer_object *bo,
         if (!radeon_ttm_bo_is_radeon_bo(bo)) {
           placement->placement = &placements;
-        placement->busy_placement = &placements;
           placement->num_placement = 1;
-        placement->num_busy_placement = 1;
           return;
       }
       rbo = container_of(bo, struct radeon_bo, tbo);
@@ -114,15 +112,11 @@ static void radeon_evict_flags(struct 
 ttm_buffer_object *bo,
                */

              radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_VRAM | RADEON_GEM_DOMAIN_GTT);
-            rbo->placement.num_busy_placement = 0;
              for (i = 0; i < rbo->placement.num_placement; i++) { if (rbo->placements[i].mem_type == TTM_PL_VRAM) { if (rbo->placements[i].fpfn < fpfn) rbo->placements[i].fpfn = fpfn;
-                } else {
-                    rbo->placement.busy_placement =
-                        &rbo->placements[i];
-                    rbo->placement.num_busy_placement = 1;
+                    rbo->placements[0].flags |= TTM_PL_FLAG_DESIRED; }
              }
          } else

drivers/gpu/drm/radeon/radeon_uvd.c +0 -1
index a2cda184b2b2..058a1c8451b2 100644
@@ -324,7 +324,6 @@ void 
 radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo,
       rbo->placements[1].fpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
       rbo->placements[1].lpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
       rbo->placement.num_placement++;
-    rbo->placement.num_busy_placement++;
   }
     void radeon_uvd_free_handles(struct radeon_device *rdev, struct drm_file *filp)
drivers/gpu/drm/ttm/ttm_bo.c +11 -5
index 8c1eaa74fa21..a5e11a92e0b9 100644
@@ -410,8 +410,8 @@ static int ttm_bo_bounce_temp_buffer(struct 
 ttm_buffer_object *bo,
       struct ttm_resource *hop_mem;
       int ret;
   -    hop_placement.num_placement = hop_placement.num_busy_placement = 1;
-    hop_placement.placement = hop_placement.busy_placement = hop;
+    hop_placement.num_placement = 1;
+    hop_placement.placement = hop;
         /* find space in the bounce domain */
       ret = ttm_bo_mem_space(bo, &hop_placement, &hop_mem, ctx);
@@ -440,10 +440,9 @@ static int ttm_bo_evict(struct 
 ttm_buffer_object *bo,
       dma_resv_assert_held(bo->base.resv);
         placement.num_placement = 0;
-    placement.num_busy_placement = 0;
       bdev->funcs->evict_flags(bo, &placement);
   -    if (!placement.num_placement && !placement.num_busy_placement) {
+    if (!placement.num_placement) {
           ret = ttm_bo_wait_ctx(bo, ctx);
           if (ret)
               return ret;
@@ -791,6 +790,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
           const struct ttm_place *place = &placement->placement[i];
           struct ttm_resource_manager *man;
   +        if (place->flags & TTM_PL_FLAG_FALLBACK)
+            continue;
+
           man = ttm_manager_type(bdev, place->mem_type);
           if (!man || !ttm_resource_manager_used(man))
               continue;
@@ -813,10 +815,13 @@ int ttm_bo_mem_space(struct 
 ttm_buffer_object *bo,
           return 0;
       }
   -    for (i = 0; i < placement->num_busy_placement; ++i) {
-        const struct ttm_place *place = &placement->busy_placement[i];
+    for (i = 0; i < placement->num_placement; ++i) {
+        const struct ttm_place *place = &placement->placement[i];
           struct ttm_resource_manager *man;
   +        if (place->flags & TTM_PL_FLAG_DESIRED)
+            continue;
+
           man = ttm_manager_type(bdev, place->mem_type);
           if (!man || !ttm_resource_manager_used(man))
               continue;
@@ -904,11 +909,11 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
       /*
        * Remove the backing store if no placement is given.
        */
-    if (!placement->num_placement && !placement->num_busy_placement)
+    if (!placement->num_placement)
           return ttm_bo_pipeline_gutting(bo);
         /* Check whether we need to move buffer. */
-    if (bo->resource && ttm_resource_compat(bo->resource, placement))
+    if (bo->resource && ttm_resource_compatible(bo->resource, 
 placement))
           return 0;
         /* Moving of pinned BOs is forbidden */
drivers/gpu/drm/ttm/ttm_resource.c +1 -1
index 02b96d23fdb9..fb14f7716cf8 100644
@@ -291,37 +291,15 @@ bool ttm_resource_intersects(struct 
 ttm_device *bdev,
   }
     /**
- * ttm_resource_compatible - test for compatibility
+ * ttm_resource_compatible - check if resource is compatible 

with placement
   *
- * @bdev: TTM device structure
- * @res: The resource to test
- * @place: The placement to test
- * @size: How many bytes the new allocation needs.
- *
- * Test if @res compatible with @place and @size.
+ * @res: the resource to check
+ * @placement: the placement to check against
   *
- * Returns true if the res placement compatible with @place and @size.
+ * Returns true if the placement is compatible.
   */

drivers/gpu/drm/ttm/ttm_resource.c +2 -20
-bool ttm_resource_compatible(struct ttm_device *bdev,
-                 struct ttm_resource *res,
-                 const struct ttm_place *place,
-                 size_t size)
-{
-    struct ttm_resource_manager *man;
-
-    if (!res || !place)
-        return false;
-
-    man = ttm_manager_type(bdev, res->mem_type);
-    if (!man->func->compatible)
-        return true;
-
-    return man->func->compatible(man, res, place, size);
-}
-
-static bool ttm_resource_places_compat(struct ttm_resource *res,
-                       const struct ttm_place *places,
-                       unsigned num_placement)
+bool ttm_resource_compatible(struct ttm_resource *res,
+                 struct ttm_placement *placement)

  {
      struct ttm_buffer_object *bo = res->bo;
      struct ttm_device *bdev = bo->bdev;

drivers/gpu/drm/ttm/ttm_resource.c +9 -1
@@ -330,44 +308,25 @@ static bool 
 ttm_resource_places_compat(struct ttm_resource *res,
       if (res->placement & TTM_PL_FLAG_TEMPORARY)
           return false;
   -    for (i = 0; i < num_placement; i++) {
-        const struct ttm_place *heap = &places[i];
+    for (i = 0; i < placement->num_placement; i++) {
+        const struct ttm_place *place = &placement->placement[i];
+        struct ttm_resource_manager *man;
   -        if (!ttm_resource_compatible(bdev, res, heap, bo->base.size))
+        if (res->mem_type != place->mem_type)
+            continue;
+
+        man = ttm_manager_type(bdev, res->mem_type);
+        if (man->func->compatible &&
+            !man->func->compatible(man, res, place, bo->base.size))
               continue;

  -        if ((res->mem_type == heap->mem_type) && -            (!(heap->flags & TTM_PL_FLAG_CONTIGUOUS) || +        if ((!(place->flags & TTM_PL_FLAG_CONTIGUOUS) || (res->placement & TTM_PL_FLAG_CONTIGUOUS))) return true;
      }
      return false;
  }
  -/**
- * ttm_resource_compat - check if resource is compatible with placement
- *
- * @res: the resource to check
- * @placement: the placement to check against
- *
- * Returns true if the placement is compatible.
- */

drivers/gpu/drm/ttm/ttm_resource.c +0 -16
-bool ttm_resource_compat(struct ttm_resource *res,
-             struct ttm_placement *placement)
-{
-    if (ttm_resource_places_compat(res, placement->placement,
-                       placement->num_placement))
-        return true;
-
-    if ((placement->busy_placement != placement->placement ||
-         placement->num_busy_placement > placement->num_placement) &&
-        ttm_resource_places_compat(res, placement->busy_placement,
-                       placement->num_busy_placement))
-        return true;
-
-    return false;
-}
-

  void ttm_resource_set_bo(struct ttm_resource *res, struct ttm_buffer_object *bo) {

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +10 -0
index 2bfac3aad7b7..bfd41ce3c8f4 100644
@@ -742,9 +742,21 @@ void vmw_bo_move_notify(struct 
 ttm_buffer_object *bo,
           vmw_resource_unbind_list(vbo);
   }
   +static u32 placement_flags(u32 domain, u32 desired, u32 fallback)
+{
+    if (desired & fallback & domain)
+        return 0;
+
+    if (desired & domain)
+        return TTM_PL_FLAG_DESIRED;
+
+    return TTM_PL_FLAG_FALLBACK;
+}
+

  static u32

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +1 -1
-set_placement_list(struct ttm_place *pl, u32 domain)
+set_placement_list(struct ttm_place *pl, u32 desired, u32 fallback)

  {
+    u32 domain = desired | fallback;
      u32 n = 0;
        /*

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +10 -5
@@ -752,35 +764,40 @@ set_placement_list(struct ttm_place *pl, 
 u32 domain)
        */
       if (domain & VMW_BO_DOMAIN_MOB) {
           pl[n].mem_type = VMW_PL_MOB;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_MOB, desired,
+                          fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;
           n++;
       }
       if (domain & VMW_BO_DOMAIN_GMR) {
           pl[n].mem_type = VMW_PL_GMR;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_GMR, desired,
+                          fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;
           n++;
       }
       if (domain & VMW_BO_DOMAIN_VRAM) {
           pl[n].mem_type = TTM_PL_VRAM;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_VRAM, desired,
+                          fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;
           n++;
       }
       if (domain & VMW_BO_DOMAIN_WAITABLE_SYS) {
           pl[n].mem_type = VMW_PL_SYSTEM;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_WAITABLE_SYS,
+                          desired, fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;
           n++;
       }
       if (domain & VMW_BO_DOMAIN_SYS) {
           pl[n].mem_type = TTM_PL_SYSTEM;
-        pl[n].flags = 0;
+        pl[n].flags = placement_flags(VMW_BO_DOMAIN_SYS, desired,
+                          fallback);
           pl[n].fpfn = 0;
           pl[n].lpfn = 0;

          n++;

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +1 -2
@@ -806,7 +823,7 @@ void vmw_bo_placement_set(struct vmw_bo *bo, 
 u32 domain, u32 busy_domain)
       u32 i;
         pl->placement = bo->places;
-    pl->num_placement = set_placement_list(bo->places, domain);
+    pl->num_placement = set_placement_list(bo->places, domain, 
 busy_domain);
         if (drm_debug_enabled(DRM_UT_DRIVER) && bo->tbo.resource) {
           for (i = 0; i < pl->num_placement; ++i) {
@@ -821,8 +838,6 @@ void vmw_bo_placement_set(struct vmw_bo *bo, 
 u32 domain, u32 busy_domain)
                    __func__, bo->tbo.resource->mem_type, domain);
       }
   -    pl->busy_placement = bo->busy_places;
-    pl->num_busy_placement = 
 set_placement_list(bo->busy_places, busy_domain);
   }

    void vmw_bo_placement_set_default_accelerated(struct vmw_bo *bo)

drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +0 -4
index a84fffcef8e1..4d23d0a70bcb 100644
@@ -46,15 +46,11 @@ static const struct ttm_place 
 sys_placement_flags = {
   struct ttm_placement vmw_vram_placement = {
       .num_placement = 1,
       .placement = &vram_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &vram_placement_flags
   };
     struct ttm_placement vmw_sys_placement = {
       .num_placement = 1,
       .placement = &sys_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &sys_placement_flags
   };
     const size_t vmw_tt_size = sizeof(struct vmw_ttm_tt);
drivers/gpu/drm/xe/xe_bo.c +15 -13
index 8e4a3b1f6b93..1e5edc7f0b85 100644
@@ -38,22 +38,26 @@ static const struct ttm_place 
 sys_placement_flags = {
   static struct ttm_placement sys_placement = {
       .num_placement = 1,
       .placement = &sys_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &sys_placement_flags,
   };
   -static const struct ttm_place tt_placement_flags = {
-    .fpfn = 0,
-    .lpfn = 0,
-    .mem_type = XE_PL_TT,
-    .flags = 0,
+static const struct ttm_place tt_placement_flags[] = {
+    {
+        .fpfn = 0,
+        .lpfn = 0,
+        .mem_type = XE_PL_TT,
+        .flags = TTM_PL_FLAG_DESIRED,
+    },
+    {
+        .fpfn = 0,
+        .lpfn = 0,
+        .mem_type = XE_PL_SYSTEM,
+        .flags = TTM_PL_FLAG_FALLBACK,
+    }
   };
     static struct ttm_placement tt_placement = {
-    .num_placement = 1,
-    .placement = &tt_placement_flags,
-    .num_busy_placement = 1,
-    .busy_placement = &sys_placement_flags,
+    .num_placement = 2,
+    .placement = tt_placement_flags,
   };
     bool mem_type_is_vram(u32 mem_type)
@@ -230,8 +234,6 @@ static int 
 __xe_bo_placement_for_flags(struct xe_device *xe, struct xe_bo *bo,
       bo->placement = (struct ttm_placement) {
           .num_placement = c,
           .placement = bo->placements,
-        .num_busy_placement = c,
-        .busy_placement = bo->placements,
       };
         return 0;
@@ -251,7 +253,6 @@ static void xe_evict_flags(struct 
 ttm_buffer_object *tbo,
           /* Don't handle scatter gather BOs */
           if (tbo->type == ttm_bo_type_sg) {
               placement->num_placement = 0;
-            placement->num_busy_placement = 0;
               return;
           }

  @@ -1353,8 +1354,6 @@ static int __xe_bo_fixed_placement(struct xe_device *xe, bo->placement = (struct ttm_placement) {
          .num_placement = 1,
          .placement = place,
-        .num_busy_placement = 1,
-        .busy_placement = place,
      };
        return 0;

drivers/gpu/drm/xe/xe_bo.c +0 -2
@@ -2112,9 +2111,7 @@ int xe_bo_migrate(struct xe_bo *bo, u32 mem_type)
         xe_place_from_ttm_type(mem_type, &requested);
       placement.num_placement = 1;
-    placement.num_busy_placement = 1;
       placement.placement = &requested;
-    placement.busy_placement = &requested;
         /*
        * Stolen needs to be handled like below VRAM handling if we ever need
include/drm/ttm/ttm_placement.h +0 -0
index 8074d0f6cae5..b510a4812609 100644
@@ -64,6 +64,12 @@
   /* For multihop handling */
   #define TTM_PL_FLAG_TEMPORARY   (1 << 2)

  +/* Placement is never used during eviction */

include/drm/ttm/ttm_placement.h +5 -0
+#define TTM_PL_FLAG_DESIRED    (1 << 3)
+
+/* Placement is only used during eviction */
+#define TTM_PL_FLAG_FALLBACK    (1 << 4)
+

  /**
   * struct ttm_place
   *

include/drm/ttm/ttm_placement.h +0 -1
@@ -86,16 +92,12 @@ struct ttm_place {
    *
    * @num_placement:    number of preferred placements
    * @placement:        preferred placements
- * @num_busy_placement:    number of preferred placements when 

need to evict buffer
- * @busy_placement:    preferred placements when need to evict buffer *
   * Structure indicating the placement you request for an object. */
  struct ttm_placement {
      unsigned        num_placement;
      const struct ttm_place    *placement;
-    unsigned        num_busy_placement;
-    const struct ttm_place    *busy_placement;
  };
    #endif

include/drm/ttm/ttm_resource.h +2 -6
index 78a226eba953..1afa13f0c22b 100644
@@ -365,12 +365,8 @@ bool ttm_resource_intersects(struct 
 ttm_device *bdev,
                    struct ttm_resource *res,
                    const struct ttm_place *place,
                    size_t size);
-bool ttm_resource_compatible(struct ttm_device *bdev,
-                 struct ttm_resource *res,
-                 const struct ttm_place *place,
-                 size_t size);
-bool ttm_resource_compat(struct ttm_resource *res,
-             struct ttm_placement *placement);
+bool ttm_resource_compatible(struct ttm_resource *res,
+                 struct ttm_placement *placement);
   void ttm_resource_set_bo(struct ttm_resource *res,
                struct ttm_buffer_object *bo);
#10 lore raw

Re: Re: Re: [PATCH 3/5] drm/ttm: replace busy placement with flags v6

Quoted 22 lines · Lucas De Marchi
Quoted 6 lines · Thomas Hellström
Quoted 4 lines · Thomas Hellström
Quoted 2 lines · Thomas Hellström

Hi, Christian

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Xe changes look good. Will send the series to xe ci to check for regressions.

Hmm, there are some checkpatch warnings about author / SOB email mismatch,

With those fixed, this patch is

it actually broke drm-tip now that this is merged:

../drivers/gpu/drm/xe/xe_bo.c:41:10: error: ‘struct ttm_placement’ has no member named ‘num_busy_placement’; did you mean ‘num_placement’

  41 |         .num_busy_placement = 1,
     |          ^~~~~~~~~~~~~~~~~~
     |          num_placement
Quoted 7 lines

../drivers/gpu/drm/xe/xe_bo.c:41:31: error: excess elements in struct initializer [-Werror]
41 | .num_busy_placement = 1,
| ^

Apparently a conflict with another patch that got applied a few days
ago: a201c6ee37d6 ("drm/xe/bo: Evict VRAM to TT rather than to system")

oh, no... apparently that commit is from a long time ago. The problem was that drm-misc-next was not yet in sync with drm-next. Thomas, do you have a fixup for this to put in rerere?

Lucas De Marchi

#11 lore raw

RE: Re: Re: [PATCH 3/5] drm/ttm: replace busy placement with flags v6

Hi Lucas,

I encountered this build issue as well. I submitted a fix for drm-tip.

Oak

Quoted 51 lines

-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Lucas De Marchi
Sent: Friday, January 26, 2024 5:23 PM
To: Thomas Hellström <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; dri- [email protected]; Christian König <[email protected]>; [email protected]
Subject: Re: Re: Re: [PATCH 3/5] drm/ttm: replace busy placement with flags v6

Quoted 13 lines · Lucas De Marchi
Quoted 12 lines · Thomas Hellström
Quoted 9 lines · Thomas Hellström
Quoted 4 lines · Thomas Hellström

Hi, Christian

Xe changes look good. Will send the series to xe ci to check for regressions.

Hmm, there are some checkpatch warnings about author / SOB email mismatch,

Quoted 8 lines
Quoted 3 lines

With those fixed, this patch is

it actually broke drm-tip now that this is merged:

../drivers/gpu/drm/xe/xe_bo.c:41:10: error: ‘struct ttm_placement’ has no

member named ‘num_busy_placement’; did you mean ‘num_placement’

Quoted 4 lines
  41 |         .num_busy_placement = 1,
     |          ^~~~~~~~~~~~~~~~~~
     |          num_placement

../drivers/gpu/drm/xe/xe_bo.c:41:31: error: excess elements in struct initializer

[-Werror]

Quoted 6 lines

41 | .num_busy_placement = 1,
| ^

Apparently a conflict with another patch that got applied a few days
ago: a201c6ee37d6 ("drm/xe/bo: Evict VRAM to TT rather than to system")

oh, no... apparently that commit is from a long time ago. The problem was that drm-misc-next was not yet in sync with drm-next. Thomas, do you have a fixup for this to put in rerere?

Lucas De Marchi

#12 lore raw

Re: Re: Re: [PATCH 3/5] drm/ttm: replace busy placement with flags v6

In reply to Lucas De Marchi
Quoted 40 lines · Lucas De Marchi
Quoted 34 lines · Lucas De Marchi
Quoted 10 lines · Thomas Hellström
Quoted 8 lines · Thomas Hellström
Quoted 5 lines · Thomas Hellström

Hi, Christian

Xe changes look good. Will send the series to xe ci to check for
regressions.

Quoted 7 lines
Quoted 3 lines

Hmm, there are some checkpatch warnings about author / SOB email
mismatch,

With those fixed, this patch is

it actually broke drm-tip now that this is merged:

../drivers/gpu/drm/xe/xe_bo.c:41:10: error: ‘struct ttm_placement’ has no member named ‘num_busy_placement’; did you mean ‘num_placement’
  41 |         .num_busy_placement = 1,
     |          ^~~~~~~~~~~~~~~~~~
     |          num_placement ../drivers/gpu/drm/xe/xe_bo.c:41:31: error: excess elements in struct initializer [-Werror]
  41 |         .num_busy_placement = 1,
     |                               ^

Quoted 4 lines

Apparently a conflict with another patch that got applied a few days
ago: a201c6ee37d6 ("drm/xe/bo: Evict VRAM to TT rather than to system")

Quoted 7 lines

oh, no... apparently that commit is  from a long time ago. The problem
was that drm-misc-next was not yet in sync with drm-next. Thomas, do you
have a fixup for this to put in rerere?

Lucas De Marchi

I added this as a manual fixup and ran some quick igt tests.

Seems to work.

#13 lore raw

PATCH 4/5 drm/ttm: improve idle/busy handling v3

In reply to Christian König

Previously we would never try to move a BO into the preferred placements when it ever landed in a busy placement since those were considered compatible.

Rework the whole handling and finally unify the idle and busy handling. ttm_bo_validate() is now responsible to try idle placement first and then use the busy placement if that didn't worked.

Drawback is that we now always try the idle placement first for each validation which might cause some additional CPU overhead on overcommit.

v2: fix kerneldoc warning and coding style
v3: take care of XE as well

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |   2 +-
 drivers/gpu/drm/ttm/ttm_bo.c               | 131 ++++++++-------------
 drivers/gpu/drm/ttm/ttm_resource.c         |  16 ++-
 drivers/gpu/drm/xe/xe_bo.c                 |   4 +-
 include/drm/ttm/ttm_bo.h                   |   3 +-
 include/drm/ttm/ttm_resource.h             |   3 +-
 7 files changed, 68 insertions(+), 93 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
index b671b0665492..06fb3fc47eaa 100644
@@ -404,7 +404,7 @@ int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,
 		(*bo_ptr)->placements[i].lpfn = (offset + size) >> PAGE_SHIFT;
 	}
 	r = ttm_bo_mem_space(&(*bo_ptr)->tbo, &(*bo_ptr)->placement,
-			     &(*bo_ptr)->tbo.resource, &ctx);
+			     &(*bo_ptr)->tbo.resource, &ctx, false);
 	if (r)
 		goto error;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
index 8722beba494e..f23cdc7c5b08 100644
@@ -966,7 +966,7 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
 	placements.mem_type = TTM_PL_TT;
 	placements.flags = bo->resource->placement;
 
-	r = ttm_bo_mem_space(bo, &placement, &tmp, &ctx);
+	r = ttm_bo_mem_space(bo, &placement, &tmp, &ctx, true);
 	if (unlikely(r))
 		return r;
 
drivers/gpu/drm/ttm/ttm_bo.c +48 -83

214 lines not on this page · raw message

drivers/gpu/drm/ttm/ttm_resource.c +12 -4
index fb14f7716cf8..65155f2013ca 100644
@@ -295,11 +295,13 @@ bool ttm_resource_intersects(struct ttm_device *bdev,
  *
  * @res: the resource to check
  * @placement: the placement to check against
+ * @evicting: true if the caller is doing evictions
  *
  * Returns true if the placement is compatible.
  */
 bool ttm_resource_compatible(struct ttm_resource *res,
-			     struct ttm_placement *placement)
+			     struct ttm_placement *placement,
+			     bool evicting)
 {
 	struct ttm_buffer_object *bo = res->bo;
 	struct ttm_device *bdev = bo->bdev;
@@ -315,14 +317,20 @@ bool ttm_resource_compatible(struct ttm_resource *res,
 		if (res->mem_type != place->mem_type)
 			continue;
 
+		if (place->flags & (evicting ? TTM_PL_FLAG_DESIRED :
+				    TTM_PL_FLAG_FALLBACK))
+			continue;
+
+		if (place->flags & TTM_PL_FLAG_CONTIGUOUS &&
+		    !(res->placement & TTM_PL_FLAG_CONTIGUOUS))
+			continue;
+
 		man = ttm_manager_type(bdev, res->mem_type);
 		if (man->func->compatible &&
 		    !man->func->compatible(man, res, place, bo->base.size))
 			continue;
 
-		if ((!(place->flags & TTM_PL_FLAG_CONTIGUOUS) ||
-		     (res->placement & TTM_PL_FLAG_CONTIGUOUS)))
-			return true;
+		return true;
 	}
 	return false;
 }
drivers/gpu/drm/xe/xe_bo.c +2 -2
index 1e5edc7f0b85..d4b8bd774ada 100644
@@ -828,7 +828,7 @@ int xe_bo_evict_pinned(struct xe_bo *bo)
 	if (WARN_ON(!xe_bo_is_vram(bo)))
 		return -EINVAL;
 
-	ret = ttm_bo_mem_space(&bo->ttm, &placement, &new_mem, &ctx);
+	ret = ttm_bo_mem_space(&bo->ttm, &placement, &new_mem, &ctx, false);
 	if (ret)
 		return ret;
 
@@ -893,7 +893,7 @@ int xe_bo_restore_pinned(struct xe_bo *bo)
 	if (WARN_ON(xe_bo_is_vram(bo) || !bo->ttm.ttm))
 		return -EINVAL;
 
-	ret = ttm_bo_mem_space(&bo->ttm, &bo->placement, &new_mem, &ctx);
+	ret = ttm_bo_mem_space(&bo->ttm, &bo->placement, &new_mem, &ctx, false);
 	if (ret)
 		return ret;
 
include/drm/ttm/ttm_bo.h +2 -1
index 0223a41a64b2..64d738f152d1 100644
@@ -397,7 +397,8 @@ vm_fault_t ttm_bo_vm_dummy_page(struct vm_fault *vmf, pgprot_t prot);
 int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 		     struct ttm_placement *placement,
 		     struct ttm_resource **mem,
-		     struct ttm_operation_ctx *ctx);
+		     struct ttm_operation_ctx *ctx,
+		     bool force_space);
 
 void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo);
 /*
include/drm/ttm/ttm_resource.h +2 -1
index 1afa13f0c22b..7561023db43d 100644
@@ -366,7 +366,8 @@ bool ttm_resource_intersects(struct ttm_device *bdev,
 			     const struct ttm_place *place,
 			     size_t size);
 bool ttm_resource_compatible(struct ttm_resource *res,
-			     struct ttm_placement *placement);
+			     struct ttm_placement *placement,
+			     bool evicting);
 void ttm_resource_set_bo(struct ttm_resource *res,
 			 struct ttm_buffer_object *bo);
 
Signature · 1 line
2.34.1
#14 lore raw

Re: [PATCH 4/5] drm/ttm: improve idle/busy handling v3

Quoted 89 lines · Christian König

Previously we would never try to move a BO into the preferred placements
when it ever landed in a busy placement since those were considered compatible.

Rework the whole handling and finally unify the idle and busy handling.
ttm_bo_validate() is now responsible to try idle placement first and then
use the busy placement if that didn't worked.

Drawback is that we now always try the idle placement first for each validation which might cause some additional CPU overhead on overcommit.

v2: fix kerneldoc warning and coding style
v3: take care of XE as well

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |   2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |   2 +- drivers/gpu/drm/ttm/ttm_bo.c               | 131 ++++++++----------- --
 drivers/gpu/drm/ttm/ttm_resource.c         |  16 ++- drivers/gpu/drm/xe/xe_bo.c                 |   4 +- include/drm/ttm/ttm_bo.h                   |   3 +- include/drm/ttm/ttm_resource.h             |   3 +-

 7 files changed, 68 insertions(+), 93 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index b671b0665492..06fb3fc47eaa 100644
@@ -404,7 +404,7 @@ int amdgpu_bo_create_kernel_at(struct
 amdgpu_device *adev,

  (*bo_ptr)->placements[i].lpfn = (offset + size) >> PAGE_SHIFT;
  }
  r = ttm_bo_mem_space(&(*bo_ptr)->tbo, &(*bo_ptr)->placement,

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
-			     &(*bo_ptr)->tbo.resource, &ctx);
+			     &(*bo_ptr)->tbo.resource, &ctx, false);

  if (r)
  goto error;

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
index 8722beba494e..f23cdc7c5b08 100644
@@ -966,7 +966,7 @@ int amdgpu_ttm_alloc_gart(struct
 ttm_buffer_object *bo)
  	placements.mem_type = TTM_PL_TT;
  	placements.flags = bo->resource->placement;

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
-	r = ttm_bo_mem_space(bo, &placement, &tmp, &ctx);
+	r = ttm_bo_mem_space(bo, &placement, &tmp, &ctx, true);

  if (unlikely(r))
  return r;

drivers/gpu/drm/ttm/ttm_bo.c +0 -0
index a5e11a92e0b9..3783be24d832 100644
@@ -414,7 +414,7 @@ static int ttm_bo_bounce_temp_buffer(struct
 ttm_buffer_object *bo,
  	hop_placement.placement = hop;


  /* find space in the bounce domain */

drivers/gpu/drm/ttm/ttm_bo.c +1 -1
-	ret = ttm_bo_mem_space(bo, &hop_placement, &hop_mem, ctx);
+	ret = ttm_bo_mem_space(bo, &hop_placement, &hop_mem, ctx,

true);
  if (ret)
  return ret;
  /* move to the bounce domain */

drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -454,7 +454,7 @@ static int ttm_bo_evict(struct ttm_buffer_object
 *bo,
  		return ttm_bo_pipeline_gutting(bo);
  	}

drivers/gpu/drm/ttm/ttm_bo.c +1 -1
-	ret = ttm_bo_mem_space(bo, &placement, &evict_mem, ctx);
+	ret = ttm_bo_mem_space(bo, &placement, &evict_mem, ctx,
Quoted 1 line

true);

This is what breaks xe's selftest since the evict-flags preferred placement is never tried so it changes the behavior.

The xe evict flags were set up to "Try to evict to TT first, but if that causes recursive eviction, try to evict to system". This here ignores the preferred eviction placement.

So "Preferred" in effect changes meaning from "Don't try this if it will cause an eviction", to "Don't try this in the evict path", which is hard for the driver to have any knowledge about.

Then also it sounds from the commit message with this patch "Preferred" also gets overloaded with "Always retry preferred on validate", but shouldn't that really be a dynamic driver decision and not something TTM should try to enforce in a static way? Drivers could have short- circuited the ttm_bo_validate() call if it succeeded once, and have a deeper thought about when to migrate from, say TT to VRAM and vice versa.

For the specific behaviour sought here, there is (or at least used to be) a construct in the vmwgfx driver that first called ttm_bo_validate() with VRAM as preferred placement and no fallback. If that failed due to VRAM being full, it called ttm_bo_validate() again, this time with fallback and VRAM allowing eviction.

/Thomas

Quoted 333 lines

  if (ret) {
  if (ret != -ERESTARTSYS) { pr_err("Failed to find memory space for buffer 0x%p eviction\n",

drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -724,37 +724,6 @@ static int ttm_bo_add_move_fence(struct
 ttm_buffer_object *bo,
  	return ret;
  }


-/*
- * Repeatedly evict memory from the LRU for @mem_type until we create enough
- * space, or we've evicted everything and there isn't enough space.
- */

drivers/gpu/drm/ttm/ttm_bo.c +0 -25
-static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
-				  const struct ttm_place *place,
-				  struct ttm_resource **mem,
-				  struct ttm_operation_ctx *ctx)
-{
-	struct ttm_device *bdev = bo->bdev;
-	struct ttm_resource_manager *man;
-	struct ww_acquire_ctx *ticket;
-	int ret;
-
-	man = ttm_manager_type(bdev, place->mem_type);
-	ticket = dma_resv_locking_ctx(bo->base.resv);
-	do {
-		ret = ttm_resource_alloc(bo, place, mem);
-		if (likely(!ret))
-			break;
-		if (unlikely(ret != -ENOSPC))
-			return ret;
-		ret = ttm_mem_evict_first(bdev, man, place, ctx,
-					  ticket);
-		if (unlikely(ret != 0))
-			return ret;
-	} while (1);
-
-	return ttm_bo_add_move_fence(bo, man, *mem, ctx-
Quoted 1 line

no_wait_gpu);

drivers/gpu/drm/ttm/ttm_bo.c +0 -2
-}
-

 /**
  * ttm_bo_mem_space
  *

drivers/gpu/drm/ttm/ttm_bo.c +1 -0
@@ -763,6 +732,7 @@ static int ttm_bo_mem_force_space(struct
 ttm_buffer_object *bo,
   * @placement: Proposed new placement for the buffer object.
   * @mem: A struct ttm_resource.
   * @ctx: if and how to sleep, lock buffers and alloc memory
+ * @force_space: If we should evict buffers to force space
   *
   * Allocate memory space for the buffer object pointed to by @bo,

using
  * the placement flags in @placement, potentially evicting other idle buffer objects.

drivers/gpu/drm/ttm/ttm_bo.c +3 -2
@@ -776,12 +746,14 @@ static int ttm_bo_mem_force_space(struct
 ttm_buffer_object *bo,
  int ttm_bo_mem_space(struct ttm_buffer_object *bo,
  			struct ttm_placement *placement,
  			struct ttm_resource **mem,
-			struct ttm_operation_ctx *ctx)
+			struct ttm_operation_ctx *ctx,
+			bool force_space)
  {
  	struct ttm_device *bdev = bo->bdev;
-	bool type_found = false;
+	struct ww_acquire_ctx *ticket;
  	int i, ret;

drivers/gpu/drm/ttm/ttm_bo.c +1 -0
+	ticket = dma_resv_locking_ctx(bo->base.resv);

  ret = dma_resv_reserve_fences(bo->base.resv, 1); if (unlikely(ret))
  return ret;

drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -790,19 +762,30 @@ int ttm_bo_mem_space(struct ttm_buffer_object
 *bo,

  const struct ttm_place *place = &placement-

Quoted 1 line

placement[i];

  struct ttm_resource_manager *man;

drivers/gpu/drm/ttm/ttm_bo.c +0 -3
-		if (place->flags & TTM_PL_FLAG_FALLBACK)
-			continue;
-

  man = ttm_manager_type(bdev, place->mem_type); if (!man || !ttm_resource_manager_used(man)) continue;

drivers/gpu/drm/ttm/ttm_bo.c +1 -3
-		type_found = true;
-		ret = ttm_resource_alloc(bo, place, mem);
-		if (ret == -ENOSPC)
+		if (place->flags & (force_space ?

TTM_PL_FLAG_DESIRED :

drivers/gpu/drm/ttm/ttm_bo.c +11 -0
+				    TTM_PL_FLAG_FALLBACK))
+			continue;
+
+		do {
+			ret = ttm_resource_alloc(bo, place, mem);
+			if (unlikely(ret != -ENOSPC))
+				return ret;
+			if (likely(!ret) || !force_space)
+				break;
+
+			ret = ttm_mem_evict_first(bdev, man, place,

ctx,

drivers/gpu/drm/ttm/ttm_bo.c +7 -0
+						  ticket);
+			if (unlikely(ret == -EBUSY))
+				break;
+			if (unlikely(ret))
+				return ret;
+		} while (1);
+		if (ret)

  continue;

drivers/gpu/drm/ttm/ttm_bo.c +0 -2
-		if (unlikely(ret))
-			goto error;


  ret = ttm_bo_add_move_fence(bo, man, *mem, ctx-

Quoted 1 line

no_wait_gpu);

  if (unlikely(ret)) {

drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -810,45 +793,19 @@ int ttm_bo_mem_space(struct ttm_buffer_object
 *bo,
  			if (ret == -EBUSY)
  				continue;

drivers/gpu/drm/ttm/ttm_bo.c +1 -1
-			goto error;
+			return ret;

  }
  return 0;
  }

drivers/gpu/drm/ttm/ttm_bo.c +0 -2
-	for (i = 0; i < placement->num_placement; ++i) {
-		const struct ttm_place *place = &placement-
Quoted 1 line

placement[i];

drivers/gpu/drm/ttm/ttm_bo.c +1 -26
-		struct ttm_resource_manager *man;
-
-		if (place->flags & TTM_PL_FLAG_DESIRED)
-			continue;
-
-		man = ttm_manager_type(bdev, place->mem_type);
-		if (!man || !ttm_resource_manager_used(man))
-			continue;
-
-		type_found = true;
-		ret = ttm_bo_mem_force_space(bo, place, mem, ctx);
-		if (likely(!ret))
-			return 0;
-
-		if (ret && ret != -EBUSY)
-			goto error;
-	}
-
-	ret = -ENOSPC;
-	if (!type_found) {
-		pr_err(TTM_PFX "No compatible memory type found\n");
-		ret = -EINVAL;
-	}
-
-error:
-	return ret;
+	return -ENOSPC;

 }
 EXPORT_SYMBOL(ttm_bo_mem_space);

 static int ttm_bo_move_buffer(struct ttm_buffer_object *bo, struct ttm_placement *placement,

drivers/gpu/drm/ttm/ttm_bo.c +2 -1
-			      struct ttm_operation_ctx *ctx)
+			      struct ttm_operation_ctx *ctx,
+			      bool force_space)

 {
  struct ttm_resource *mem;
  struct ttm_place hop;

drivers/gpu/drm/ttm/ttm_bo.c +1 -1
@@ -865,7 +822,7 @@ static int ttm_bo_move_buffer(struct
 ttm_buffer_object *bo,
  	 * stop and the driver will be called to make
  	 * the second hop.
  	 */
-	ret = ttm_bo_mem_space(bo, placement, &mem, ctx);
+	ret = ttm_bo_mem_space(bo, placement, &mem, ctx,
 force_space);
  	if (ret)

  return ret;
 bounce:

drivers/gpu/drm/ttm/ttm_bo.c +1 -0
@@ -902,6 +859,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
  		    struct ttm_placement *placement,
  		    struct ttm_operation_ctx *ctx)
  {
+	bool force_space;
  	int ret;


  dma_resv_assert_held(bo->base.resv);

drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -912,20 +870,27 @@ int ttm_bo_validate(struct ttm_buffer_object
 *bo,
  	if (!placement->num_placement)
  		return ttm_bo_pipeline_gutting(bo);

drivers/gpu/drm/ttm/ttm_bo.c +0 -2
-	/* Check whether we need to move buffer. */
-	if (bo->resource && ttm_resource_compatible(bo->resource,

placement))

drivers/gpu/drm/ttm/ttm_bo.c +11 -1
-		return 0;
+	force_space = false;
+	do {
+		/* Check whether we need to move buffer. */
+		if (bo->resource &&
+		    ttm_resource_compatible(bo->resource, placement,
+					    force_space))
+			return 0;
+
+		/* Moving of pinned BOs is forbidden */
+		if (bo->pin_count)
+			return -EINVAL;

drivers/gpu/drm/ttm/ttm_bo.c +1 -3
-	/* Moving of pinned BOs is forbidden */
-	if (bo->pin_count)
-		return -EINVAL;
+		ret = ttm_bo_move_buffer(bo, placement, ctx,

force_space);

drivers/gpu/drm/ttm/ttm_bo.c +2 -0
+		if (ret && ret != -ENOSPC)
+			return ret;

drivers/gpu/drm/ttm/ttm_bo.c +2 -1
-	ret = ttm_bo_move_buffer(bo, placement, ctx);
+		force_space = !force_space;
+	} while (force_space);

  /* For backward compatibility with userspace */ if (ret == -ENOSPC)
  return -ENOMEM;

drivers/gpu/drm/ttm/ttm_bo.c +0 -2
-	if (ret)
-		return ret;


  /*
  * We might need to add a TTM.

drivers/gpu/drm/ttm/ttm_resource.c +3 -1
index fb14f7716cf8..65155f2013ca 100644
@@ -295,11 +295,13 @@ bool ttm_resource_intersects(struct ttm_device
 *bdev,
   *
   * @res: the resource to check
   * @placement: the placement to check against
+ * @evicting: true if the caller is doing evictions
   *
   * Returns true if the placement is compatible.
   */
  bool ttm_resource_compatible(struct ttm_resource *res,
-			     struct ttm_placement *placement)
+			     struct ttm_placement *placement,
+			     bool evicting)
  {
  	struct ttm_buffer_object *bo = res->bo;

  struct ttm_device *bdev = bo->bdev;

drivers/gpu/drm/ttm/ttm_resource.c +0 -0
@@ -315,14 +317,20 @@ bool ttm_resource_compatible(struct
 ttm_resource *res,
  		if (res->mem_type != place->mem_type)
  			continue;

drivers/gpu/drm/ttm/ttm_resource.c +8 -0
+		if (place->flags & (evicting ? TTM_PL_FLAG_DESIRED :
+				    TTM_PL_FLAG_FALLBACK))
+			continue;
+
+		if (place->flags & TTM_PL_FLAG_CONTIGUOUS &&
+		    !(res->placement & TTM_PL_FLAG_CONTIGUOUS))
+			continue;
+

  man = ttm_manager_type(bdev, res->mem_type); if (man->func->compatible && !man->func->compatible(man, res, place, bo-

Quoted 1 line

base.size))

  continue;

drivers/gpu/drm/ttm/ttm_resource.c +1 -3
-		if ((!(place->flags & TTM_PL_FLAG_CONTIGUOUS) ||
-		     (res->placement & TTM_PL_FLAG_CONTIGUOUS)))
-			return true;
+		return true;

  }
  return false;
 }

drivers/gpu/drm/xe/xe_bo.c +0 -0
index 1e5edc7f0b85..d4b8bd774ada 100644
@@ -828,7 +828,7 @@ int xe_bo_evict_pinned(struct xe_bo *bo)
  	if (WARN_ON(!xe_bo_is_vram(bo)))
  		return -EINVAL;

drivers/gpu/drm/xe/xe_bo.c +0 -1
-	ret = ttm_bo_mem_space(&bo->ttm, &placement, &new_mem,

&ctx);

drivers/gpu/drm/xe/xe_bo.c +1 -0
+	ret = ttm_bo_mem_space(&bo->ttm, &placement, &new_mem, &ctx,

false);
  if (ret)
  return ret;

drivers/gpu/drm/xe/xe_bo.c +0 -0
@@ -893,7 +893,7 @@ int xe_bo_restore_pinned(struct xe_bo *bo)
  	if (WARN_ON(xe_bo_is_vram(bo) || !bo->ttm.ttm))
  		return -EINVAL;

drivers/gpu/drm/xe/xe_bo.c +0 -1
-	ret = ttm_bo_mem_space(&bo->ttm, &bo->placement, &new_mem,

&ctx);

drivers/gpu/drm/xe/xe_bo.c +1 -0
+	ret = ttm_bo_mem_space(&bo->ttm, &bo->placement, &new_mem,

&ctx, false);
  if (ret)
  return ret;

include/drm/ttm/ttm_bo.h +2 -1
index 0223a41a64b2..64d738f152d1 100644
@@ -397,7 +397,8 @@ vm_fault_t ttm_bo_vm_dummy_page(struct vm_fault
 *vmf, pgprot_t prot);
  int ttm_bo_mem_space(struct ttm_buffer_object *bo,
  		     struct ttm_placement *placement,
  		     struct ttm_resource **mem,
-		     struct ttm_operation_ctx *ctx);
+		     struct ttm_operation_ctx *ctx,
+		     bool force_space);


 void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo); /*

include/drm/ttm/ttm_resource.h +2 -1
index 1afa13f0c22b..7561023db43d 100644
@@ -366,7 +366,8 @@ bool ttm_resource_intersects(struct ttm_device
 *bdev,
  			     const struct ttm_place *place,
  			     size_t size);
  bool ttm_resource_compatible(struct ttm_resource *res,
-			     struct ttm_placement *placement);
+			     struct ttm_placement *placement,
+			     bool evicting);
  void ttm_resource_set_bo(struct ttm_resource *res,
  			 struct ttm_buffer_object *bo);

#15 lore raw

Re: [PATCH 4/5] drm/ttm: improve idle/busy handling v3

Quoted 108 lines · Thomas Hellström
Quoted 81 lines · Christian König

Previously we would never try to move a BO into the preferred placements
when it ever landed in a busy placement since those were considered compatible.

Rework the whole handling and finally unify the idle and busy handling.
ttm_bo_validate() is now responsible to try idle placement first and then
use the busy placement if that didn't worked.

Drawback is that we now always try the idle placement first for each validation which might cause some additional CPU overhead on overcommit.

v2: fix kerneldoc warning and coding style
v3: take care of XE as well

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |   2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |   2 +-
  drivers/gpu/drm/ttm/ttm_bo.c               | 131 ++++++++-----------
--
  drivers/gpu/drm/ttm/ttm_resource.c         |  16 ++-
  drivers/gpu/drm/xe/xe_bo.c                 |   4 +-
  include/drm/ttm/ttm_bo.h                   |   3 +-
  include/drm/ttm/ttm_resource.h             |   3 +-
  7 files changed, 68 insertions(+), 93 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
index b671b0665492..06fb3fc47eaa 100644
@@ -404,7 +404,7 @@ int amdgpu_bo_create_kernel_at(struct
 amdgpu_device *adev,
  		(*bo_ptr)->placements[i].lpfn = (offset + size) >>
 PAGE_SHIFT;
  	}
  	r = ttm_bo_mem_space(&(*bo_ptr)->tbo, &(*bo_ptr)->placement,
-			     &(*bo_ptr)->tbo.resource, &ctx);
+			     &(*bo_ptr)->tbo.resource, &ctx, false);
  	if (r)

  goto error;

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
index 8722beba494e..f23cdc7c5b08 100644
@@ -966,7 +966,7 @@ int amdgpu_ttm_alloc_gart(struct
 ttm_buffer_object *bo)
  	placements.mem_type = TTM_PL_TT;
  	placements.flags = bo->resource->placement;
 
-	r = ttm_bo_mem_space(bo, &placement, &tmp, &ctx);
+	r = ttm_bo_mem_space(bo, &placement, &tmp, &ctx, true);
  	if (unlikely(r))
  		return r;
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
index a5e11a92e0b9..3783be24d832 100644
@@ -414,7 +414,7 @@ static int ttm_bo_bounce_temp_buffer(struct
 ttm_buffer_object *bo,
  	hop_placement.placement = hop;
 
  	/* find space in the bounce domain */
-	ret = ttm_bo_mem_space(bo, &hop_placement, &hop_mem, ctx);
+	ret = ttm_bo_mem_space(bo, &hop_placement, &hop_mem, ctx,
 true);
  	if (ret)

  return ret;
  /* move to the bounce domain */

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_evict(struct ttm_buffer_object · line 459

Quoted 7 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
@@ -454,7 +454,7 @@ static int ttm_bo_evict(struct ttm_buffer_object
 *bo,
  		return ttm_bo_pipeline_gutting(bo);
  	}
 
-	ret = ttm_bo_mem_space(bo, &placement, &evict_mem, ctx);
+	ret = ttm_bo_mem_space(bo, &placement, &evict_mem, ctx,
 true);

This is what breaks xe's selftest since the evict-flags preferred placement is never tried so it changes the behavior.

The xe evict flags were set up to "Try to evict to TT first, but if that causes recursive eviction, try to evict to system". This here ignores the preferred eviction placement.

So "Preferred" in effect changes meaning from "Don't try this if it will cause an eviction", to "Don't try this in the evict path", which is hard for the driver to have any knowledge about.

Then also it sounds from the commit message with this patch "Preferred" also gets overloaded with "Always retry preferred on validate", but shouldn't that really be a dynamic driver decision and not something TTM should try to enforce in a static way? Drivers could have short- circuited the ttm_bo_validate() call if it succeeded once, and have a deeper thought about when to migrate from, say TT to VRAM and vice versa.

Quoted 8 lines

For the specific behaviour sought here, there is (or at least used to be) a construct in the vmwgfx driver that first called ttm_bo_validate() with VRAM as preferred placement and no fallback. If that failed due to VRAM being full, it called ttm_bo_validate() again, this time with fallback and VRAM allowing eviction.

/Thomas

To conclude here, a suggestion would be,

1) Could we separate the semantics of the "Preferred" flag. Perhaps creating yet another one. first flag: "Retry this placement even if bo is in a valid placement"
second flag: "Don't use this placement if it would cause an eviction" (Retain old semantics)

Although I think the first flag behaviour can be easily implemented with a driver specific xxx_bo_validate(), I'm not against having that in TTM as well.

2) Please keep the old behaviour of the eviction flags? Meaning even for eviction we have preferred and fallback placements. It comes in handy when pipelining (always evicting to SYSTEM requires syncing), and if opportunistically trying to evict to other VRAM memory types on multi-tile. I see no easy way to otherwise hook into TTM to implement that if the behaviour is changed as suggested.

Thanks,

Thomas

Quoted 335 lines
Quoted 335 lines
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
  	if (ret) {

  if (ret != -ERESTARTSYS) { pr_err("Failed to find memory space for
buffer 0x%p eviction\n",

drivers/gpu/drm/ttm/ttm_bo.c +0 -2
@@ -724,37 +724,6 @@ static int ttm_bo_add_move_fence(struct
 ttm_buffer_object *bo,
  	return ret;
  }
 
-/*
- * Repeatedly evict memory from the LRU for @mem_type until we

create enough
- * space, or we've evicted everything and there isn't enough space.
- */

drivers/gpu/drm/ttm/ttm_bo.c +0 -25
-static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
-				  const struct ttm_place *place,
-				  struct ttm_resource **mem,
-				  struct ttm_operation_ctx *ctx)
-{
-	struct ttm_device *bdev = bo->bdev;
-	struct ttm_resource_manager *man;
-	struct ww_acquire_ctx *ticket;
-	int ret;
-
-	man = ttm_manager_type(bdev, place->mem_type);
-	ticket = dma_resv_locking_ctx(bo->base.resv);
-	do {
-		ret = ttm_resource_alloc(bo, place, mem);
-		if (likely(!ret))
-			break;
-		if (unlikely(ret != -ENOSPC))
-			return ret;
-		ret = ttm_mem_evict_first(bdev, man, place, ctx,
-					  ticket);
-		if (unlikely(ret != 0))
-			return ret;
-	} while (1);
-
-	return ttm_bo_add_move_fence(bo, man, *mem, ctx-
Quoted 1 line

no_wait_gpu);

drivers/gpu/drm/ttm/ttm_bo.c +1 -2
-}
-
  /**
   * ttm_bo_mem_space
   *
@@ -763,6 +732,7 @@ static int ttm_bo_mem_force_space(struct
 ttm_buffer_object *bo,
   * @placement: Proposed new placement for the buffer object.
   * @mem: A struct ttm_resource.
   * @ctx: if and how to sleep, lock buffers and alloc memory
+ * @force_space: If we should evict buffers to force space
   *
   * Allocate memory space for the buffer object pointed to by @bo,

using
  * the placement flags in @placement, potentially evicting other
idle buffer objects.

drivers/gpu/drm/ttm/ttm_bo.c +4 -2
@@ -776,12 +746,14 @@ static int ttm_bo_mem_force_space(struct
 ttm_buffer_object *bo,
  int ttm_bo_mem_space(struct ttm_buffer_object *bo,
  			struct ttm_placement *placement,
  			struct ttm_resource **mem,
-			struct ttm_operation_ctx *ctx)
+			struct ttm_operation_ctx *ctx,
+			bool force_space)
  {
  	struct ttm_device *bdev = bo->bdev;
-	bool type_found = false;
+	struct ww_acquire_ctx *ticket;
  	int i, ret;
 
+	ticket = dma_resv_locking_ctx(bo->base.resv);
  	ret = dma_resv_reserve_fences(bo->base.resv, 1);
  	if (unlikely(ret))

  return ret;

drivers/gpu/drm/ttm/ttm_bo.c +1 -6
@@ -790,19 +762,30 @@ int ttm_bo_mem_space(struct ttm_buffer_object
 *bo,
  		const struct ttm_place *place = &placement-
 > placement[i];
  		struct ttm_resource_manager *man;
 
-		if (place->flags & TTM_PL_FLAG_FALLBACK)
-			continue;
-
  		man = ttm_manager_type(bdev, place->mem_type);
  		if (!man || !ttm_resource_manager_used(man))
  			continue;
 
-		type_found = true;
-		ret = ttm_resource_alloc(bo, place, mem);
-		if (ret == -ENOSPC)
+		if (place->flags & (force_space ?

TTM_PL_FLAG_DESIRED :

drivers/gpu/drm/ttm/ttm_bo.c +11 -0
+				    TTM_PL_FLAG_FALLBACK))
+			continue;
+
+		do {
+			ret = ttm_resource_alloc(bo, place, mem);
+			if (unlikely(ret != -ENOSPC))
+				return ret;
+			if (likely(!ret) || !force_space)
+				break;
+
+			ret = ttm_mem_evict_first(bdev, man, place,

ctx,

drivers/gpu/drm/ttm/ttm_bo.c +7 -2
+						  ticket);
+			if (unlikely(ret == -EBUSY))
+				break;
+			if (unlikely(ret))
+				return ret;
+		} while (1);
+		if (ret)
  			continue;
-		if (unlikely(ret))
-			goto error;
 
  		ret = ttm_bo_add_move_fence(bo, man, *mem, ctx-
Quoted 1 line

no_wait_gpu);

  if (unlikely(ret)) {

drivers/gpu/drm/ttm/ttm_bo.c +4 -30
@@ -810,45 +793,19 @@ int ttm_bo_mem_space(struct ttm_buffer_object
 *bo,
  			if (ret == -EBUSY)
  				continue;
 
-			goto error;
+			return ret;
  		}
  		return 0;
  	}
 
-	for (i = 0; i < placement->num_placement; ++i) {
-		const struct ttm_place *place = &placement-
 > placement[i];
-		struct ttm_resource_manager *man;
-
-		if (place->flags & TTM_PL_FLAG_DESIRED)
-			continue;
-
-		man = ttm_manager_type(bdev, place->mem_type);
-		if (!man || !ttm_resource_manager_used(man))
-			continue;
-
-		type_found = true;
-		ret = ttm_bo_mem_force_space(bo, place, mem, ctx);
-		if (likely(!ret))
-			return 0;
-
-		if (ret && ret != -EBUSY)
-			goto error;
-	}
-
-	ret = -ENOSPC;
-	if (!type_found) {
-		pr_err(TTM_PFX "No compatible memory type found\n");
-		ret = -EINVAL;
-	}
-
-error:
-	return ret;
+	return -ENOSPC;
  }
  EXPORT_SYMBOL(ttm_bo_mem_space);
 
  static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
  			      struct ttm_placement *placement,
-			      struct ttm_operation_ctx *ctx)
+			      struct ttm_operation_ctx *ctx,
+			      bool force_space)
  {

  struct ttm_resource *mem;
  struct ttm_place hop;

drivers/gpu/drm/ttm/ttm_bo.c +1 -1
@@ -865,7 +822,7 @@ static int ttm_bo_move_buffer(struct
 ttm_buffer_object *bo,
  	 * stop and the driver will be called to make
  	 * the second hop.
  	 */
-	ret = ttm_bo_mem_space(bo, placement, &mem, ctx);
+	ret = ttm_bo_mem_space(bo, placement, &mem, ctx,
 force_space);
  	if (ret)

  return ret;
 bounce:

drivers/gpu/drm/ttm/ttm_bo.c +17 -9
@@ -902,6 +859,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
  		    struct ttm_placement *placement,
  		    struct ttm_operation_ctx *ctx)
  {
+	bool force_space;
  	int ret;
 
  	dma_resv_assert_held(bo->base.resv);
@@ -912,20 +870,27 @@ int ttm_bo_validate(struct ttm_buffer_object
 *bo,
  	if (!placement->num_placement)
  		return ttm_bo_pipeline_gutting(bo);
 
-	/* Check whether we need to move buffer. */
-	if (bo->resource && ttm_resource_compatible(bo->resource,
 placement))
-		return 0;
+	force_space = false;
+	do {
+		/* Check whether we need to move buffer. */
+		if (bo->resource &&
+		    ttm_resource_compatible(bo->resource, placement,
+					    force_space))
+			return 0;
+
+		/* Moving of pinned BOs is forbidden */
+		if (bo->pin_count)
+			return -EINVAL;
 
-	/* Moving of pinned BOs is forbidden */
-	if (bo->pin_count)
-		return -EINVAL;
+		ret = ttm_bo_move_buffer(bo, placement, ctx,
 force_space);
+		if (ret && ret != -ENOSPC)
+			return ret;
 
-	ret = ttm_bo_move_buffer(bo, placement, ctx);
+		force_space = !force_space;
+	} while (force_space);
  	/* For backward compatibility with userspace */
  	if (ret == -ENOSPC)
  		return -ENOMEM;
-	if (ret)
-		return ret;

  /*
  * We might need to add a TTM.

drivers/gpu/drm/ttm/ttm_resource.c +3 -1
index fb14f7716cf8..65155f2013ca 100644
@@ -295,11 +295,13 @@ bool ttm_resource_intersects(struct ttm_device
 *bdev,
   *
   * @res: the resource to check
   * @placement: the placement to check against
+ * @evicting: true if the caller is doing evictions
   *
   * Returns true if the placement is compatible.
   */
  bool ttm_resource_compatible(struct ttm_resource *res,
-			     struct ttm_placement *placement)
+			     struct ttm_placement *placement,
+			     bool evicting)
  {
  	struct ttm_buffer_object *bo = res->bo;

  struct ttm_device *bdev = bo->bdev;

drivers/gpu/drm/ttm/ttm_resource.c +9 -3
@@ -315,14 +317,20 @@ bool ttm_resource_compatible(struct
 ttm_resource *res,
  		if (res->mem_type != place->mem_type)
  			continue;
 
+		if (place->flags & (evicting ? TTM_PL_FLAG_DESIRED :
+				    TTM_PL_FLAG_FALLBACK))
+			continue;
+
+		if (place->flags & TTM_PL_FLAG_CONTIGUOUS &&
+		    !(res->placement & TTM_PL_FLAG_CONTIGUOUS))
+			continue;
+
  		man = ttm_manager_type(bdev, res->mem_type);
  		if (man->func->compatible &&
  		    !man->func->compatible(man, res, place, bo-
 > base.size))
  			continue;
 
-		if ((!(place->flags & TTM_PL_FLAG_CONTIGUOUS) ||
-		     (res->placement & TTM_PL_FLAG_CONTIGUOUS)))
-			return true;
+		return true;
  	}

  return false;
 }

drivers/gpu/drm/xe/xe_bo.c +1 -1
index 1e5edc7f0b85..d4b8bd774ada 100644
@@ -828,7 +828,7 @@ int xe_bo_evict_pinned(struct xe_bo *bo)
  	if (WARN_ON(!xe_bo_is_vram(bo)))
  		return -EINVAL;
 
-	ret = ttm_bo_mem_space(&bo->ttm, &placement, &new_mem,
 &ctx);
+	ret = ttm_bo_mem_space(&bo->ttm, &placement, &new_mem, &ctx,
 false);
  	if (ret)

  return ret;

drivers/gpu/drm/xe/xe_bo.c +1 -1
@@ -893,7 +893,7 @@ int xe_bo_restore_pinned(struct xe_bo *bo)
  	if (WARN_ON(xe_bo_is_vram(bo) || !bo->ttm.ttm))
  		return -EINVAL;
 
-	ret = ttm_bo_mem_space(&bo->ttm, &bo->placement, &new_mem,
 &ctx);
+	ret = ttm_bo_mem_space(&bo->ttm, &bo->placement, &new_mem,
 &ctx, false);
  	if (ret)

  return ret;

include/drm/ttm/ttm_bo.h +2 -1
index 0223a41a64b2..64d738f152d1 100644
@@ -397,7 +397,8 @@ vm_fault_t ttm_bo_vm_dummy_page(struct vm_fault
 *vmf, pgprot_t prot);
  int ttm_bo_mem_space(struct ttm_buffer_object *bo,
  		     struct ttm_placement *placement,
  		     struct ttm_resource **mem,
-		     struct ttm_operation_ctx *ctx);
+		     struct ttm_operation_ctx *ctx,
+		     bool force_space);
 
  void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo);

 /*

include/drm/ttm/ttm_resource.h +2 -1
index 1afa13f0c22b..7561023db43d 100644
@@ -366,7 +366,8 @@ bool ttm_resource_intersects(struct ttm_device
 *bdev,
  			     const struct ttm_place *place,
  			     size_t size);
  bool ttm_resource_compatible(struct ttm_resource *res,
-			     struct ttm_placement *placement);
+			     struct ttm_placement *placement,
+			     bool evicting);
  void ttm_resource_set_bo(struct ttm_resource *res,
  			 struct ttm_buffer_object *bo);
#16 lore raw

PATCH 5/5 drm/amdgpu: use GTT only as fallback for VRAM|GTT

In reply to Christian König

Try to fill up VRAM as well by setting the busy flag on GTT allocations.

This fixes the issue that when VRAM was evacuated for suspend it's never filled up again unless the application is restarted.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6 -0
index 06fb3fc47eaa..2752f2a67a44 100644
@@ -173,6 +173,12 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain)
 			abo->flags & AMDGPU_GEM_CREATE_PREEMPTIBLE ?
 			AMDGPU_PL_PREEMPT : TTM_PL_TT;
 		places[c].flags = 0;
+		/*
+		 * When GTT is just an alternative to VRAM make sure that we
+		 * only use it as fallback and still try to fill up VRAM first.
+		 */
+		if (domain & abo->preferred_domains & AMDGPU_GEM_DOMAIN_VRAM)
+			places[c].flags |= TTM_PL_FLAG_FALLBACK;
 		c++;
 	}
 
Signature · 1 line
2.34.1
#17 lore raw

✗ Fi.CI.CHECKPATCH: warning for series starting with [1/5] drm/vmwgfx: remove vmw_vram_gmr_placement

In reply to Christian König
== Series Details ==

== Series Details ==

Series: series starting with [1/5] drm/vmwgfx: remove vmw_vram_gmr_placement
URL : https://patchwork.freedesktop.org/series/128718/
State : warning

== Summary ==

Error: dim checkpatch failed
5d2dcc20fde0 drm/vmwgfx: remove vmw_vram_gmr_placement
-:70: WARNING:FROM_SIGN_OFF_MISMATCH: From:/Signed-off-by: email address mismatch: 'From: "Christian König" <[email protected]>' != 'Signed-off-by: Christian König <[email protected]>'

total: 0 errors, 1 warnings, 0 checks, 47 lines checked
eca5f869c1ea drm/ttm: return ENOSPC from ttm_bo_mem_space
-:38: WARNING:FROM_SIGN_OFF_MISMATCH: From:/Signed-off-by: email address mismatch: 'From: "Christian König" <[email protected]>' != 'Signed-off-by: Christian König <[email protected]>'

total: 0 errors, 1 warnings, 0 checks, 17 lines checked
00a0f7e4a906 drm/ttm: replace busy placement with flags v6
9bd2216484a4 drm/ttm: improve idle/busy handling v3
-:371: WARNING:FROM_SIGN_OFF_MISMATCH: From:/Signed-off-by: email address mismatch: 'From: "Christian König" <[email protected]>' != 'Signed-off-by: Christian König <[email protected]>'

total: 0 errors, 1 warnings, 0 checks, 301 lines checked
e865123245af drm/amdgpu: use GTT only as fallback for VRAM|GTT
-:32: WARNING:FROM_SIGN_OFF_MISMATCH: From:/Signed-off-by: email address mismatch: 'From: "Christian König" <[email protected]>' != 'Signed-off-by: Christian König <[email protected]>'

total: 0 errors, 1 warnings, 0 checks, 12 lines checked

#18 lore raw

✗ Fi.CI.SPARSE: warning for series starting with [1/5] drm/vmwgfx: remove vmw_vram_gmr_placement

In reply to Christian König
== Series Details ==

== Series Details ==

Series: series starting with [1/5] drm/vmwgfx: remove vmw_vram_gmr_placement
URL : https://patchwork.freedesktop.org/series/128718/
State : warning

== Summary ==

Error: dim sparse failed
Sparse version: v0.6.2
Fast mode used, each commit won't be checked separately.

#19 lore raw

✗ Fi.CI.BAT: failure for series starting with [1/5] drm/vmwgfx: remove vmw_vram_gmr_placement

In reply to Christian König
== Series Details ==

== Series Details ==

Series: series starting with [1/5] drm/vmwgfx: remove vmw_vram_gmr_placement
URL : https://patchwork.freedesktop.org/series/128718/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_14118 -> Patchwork_128718v1
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_128718v1 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes
introduced in Patchwork_128718v1, please notify your bug team ([email protected]) to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/index.html

Participating hosts (29 -> 38)
------------------------------

Additional (10): bat-kbl-2 fi-tgl-1115g4 bat-dg2-9 fi-apl-guc fi-glk-j4005 fi-ivb-3770 bat-atsm-1 fi-pnv-d510 bat-rplp-1 fi-bsw-nick
Missing (1): fi-snb-2520m

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_128718v1:

### IGT changes ###

#### Possible regressions ####

* igt@gem_exec_suspend@basic-s0@smem:
- fi-rkl-11600: [PASS][1] -> [FAIL][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14118/fi-rkl-11600/igt@gem_exec_suspend@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-rkl-11600/igt@gem_exec_suspend@[email protected]

* igt@i915_selftest@live@gem_contexts:
- bat-adlm-1: [PASS][3] -> [INCOMPLETE][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14118/bat-adlm-1/igt@i915_selftest@live@gem_contexts.html
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-adlm-1/igt@i915_selftest@live@gem_contexts.html

* igt@kms_pipe_crc_basic@suspend-read-crc@pipe-b-hdmi-a-1:
- bat-rpls-2: [PASS][5] -> [ABORT][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14118/bat-rpls-2/igt@kms_pipe_crc_basic@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-rpls-2/igt@kms_pipe_crc_basic@[email protected]

Known issues
------------

Here are the changes found in Patchwork_128718v1 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@debugfs_test@basic-hwmon:
- bat-rplp-1: NOTRUN -> [SKIP][7] ([i915#9318])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-rplp-1/igt@[email protected]
- fi-tgl-1115g4: NOTRUN -> [SKIP][8] ([i915#9318])
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-tgl-1115g4/igt@[email protected]

* igt@fbdev@info:
- bat-kbl-2: NOTRUN -> [SKIP][9] ([fdo#109271] / [i915#1849])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-kbl-2/igt@[email protected]

* igt@gem_huc_copy@huc-copy:
- fi-tgl-1115g4: NOTRUN -> [SKIP][10] ([i915#2190])
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-tgl-1115g4/igt@[email protected]
- fi-glk-j4005: NOTRUN -> [SKIP][11] ([fdo#109271] / [i915#2190])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-glk-j4005/igt@[email protected]

* igt@gem_lmem_swapping@basic:
- fi-apl-guc: NOTRUN -> [SKIP][12] ([fdo#109271] / [i915#4613]) +3 other tests skip
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-apl-guc/igt@[email protected]
- fi-pnv-d510: NOTRUN -> [SKIP][13] ([fdo#109271]) +31 other tests skip
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-pnv-d510/igt@[email protected]
- fi-glk-j4005: NOTRUN -> [SKIP][14] ([fdo#109271] / [i915#4613]) +3 other tests skip
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-glk-j4005/igt@[email protected]

* igt@gem_lmem_swapping@parallel-random-engines:
- fi-bsw-nick: NOTRUN -> [SKIP][15] ([fdo#109271]) +15 other tests skip
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-bsw-nick/igt@[email protected]
- bat-kbl-2: NOTRUN -> [SKIP][16] ([fdo#109271]) +36 other tests skip
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-kbl-2/igt@[email protected]
- bat-rplp-1: NOTRUN -> [SKIP][17] ([i915#4613]) +3 other tests skip
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-rplp-1/igt@[email protected]
- fi-tgl-1115g4: NOTRUN -> [SKIP][18] ([i915#4613]) +3 other tests skip
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-tgl-1115g4/igt@[email protected]

* igt@gem_mmap@basic:
- bat-atsm-1: NOTRUN -> [SKIP][19] ([i915#4083])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@[email protected]
- bat-dg2-9: NOTRUN -> [SKIP][20] ([i915#4083])
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

* igt@gem_mmap_gtt@basic:
- bat-dg2-9: NOTRUN -> [SKIP][21] ([i915#4077]) +2 other tests skip
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

* igt@gem_render_tiled_blits@basic:
- bat-dg2-9: NOTRUN -> [SKIP][22] ([i915#4079]) +1 other test skip
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

* igt@gem_tiled_fence_blits@basic:
- bat-atsm-1: NOTRUN -> [SKIP][23] ([i915#4077]) +2 other tests skip
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@[email protected]

* igt@gem_tiled_pread_basic:
- bat-atsm-1: NOTRUN -> [SKIP][24] ([i915#4079]) +1 other test skip
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@gem_tiled_pread_basic.html
- bat-rplp-1: NOTRUN -> [SKIP][25] ([i915#3282])
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-rplp-1/igt@gem_tiled_pread_basic.html

* igt@i915_pm_rps@basic-api:
- bat-rplp-1: NOTRUN -> [SKIP][26] ([i915#6621])
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-rplp-1/igt@[email protected]
- bat-atsm-1: NOTRUN -> [SKIP][27] ([i915#6621])
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@[email protected]
- bat-dg2-9: NOTRUN -> [SKIP][28] ([i915#6621])
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

* igt@i915_suspend@basic-s3-without-i915:
- fi-kbl-7567u: [PASS][29] -> [INCOMPLETE][30] ([i915#4817])
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14118/fi-kbl-7567u/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-kbl-7567u/igt@[email protected]
- fi-tgl-1115g4: NOTRUN -> [INCOMPLETE][31] ([i915#7443])
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-tgl-1115g4/igt@[email protected]
- bat-atsm-1: NOTRUN -> [SKIP][32] ([i915#6645])
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@[email protected]

* igt@kms_addfb_basic@addfb25-y-tiled-small-legacy:
- bat-dg2-9: NOTRUN -> [SKIP][33] ([i915#5190])
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

* igt@kms_addfb_basic@basic-y-tiled-legacy:
- bat-dg2-9: NOTRUN -> [SKIP][34] ([i915#4215] / [i915#5190])
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

* igt@kms_addfb_basic@framebuffer-vs-set-tiling:
- bat-dg2-9: NOTRUN -> [SKIP][35] ([i915#4212]) +7 other tests skip
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

* igt@kms_addfb_basic@size-max:
- bat-atsm-1: NOTRUN -> [SKIP][36] ([i915#6077]) +37 other tests skip
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@[email protected]

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-atomic:
- fi-glk-j4005: NOTRUN -> [SKIP][37] ([fdo#109271]) +6 other tests skip
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-glk-j4005/igt@[email protected]
- fi-tgl-1115g4: NOTRUN -> [SKIP][38] ([i915#4103]) +1 other test skip
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-tgl-1115g4/igt@[email protected]

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-legacy:
- bat-rplp-1: NOTRUN -> [SKIP][39] ([i915#4103] / [i915#4213]) +1 other test skip
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-rplp-1/igt@[email protected]
- bat-dg2-9: NOTRUN -> [SKIP][40] ([i915#4103] / [i915#4213]) +1 other test skip
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

* igt@kms_cursor_legacy@basic-flip-after-cursor-atomic:
- bat-atsm-1: NOTRUN -> [SKIP][41] ([i915#6078]) +17 other tests skip
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@[email protected]

* igt@kms_dsc@dsc-basic:
- bat-rplp-1: NOTRUN -> [SKIP][42] ([i915#3555] / [i915#3840])
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-rplp-1/igt@[email protected]
- fi-tgl-1115g4: NOTRUN -> [SKIP][43] ([i915#3555] / [i915#3840])
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-tgl-1115g4/igt@[email protected]

* igt@kms_force_connector_basic@force-load-detect:
- bat-rplp-1: NOTRUN -> [SKIP][44] ([fdo#109285])
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-rplp-1/igt@[email protected]
- fi-tgl-1115g4: NOTRUN -> [SKIP][45] ([fdo#109285])
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-tgl-1115g4/igt@[email protected]
- bat-dg2-9: NOTRUN -> [SKIP][46] ([fdo#109285])
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

* igt@kms_force_connector_basic@prune-stale-modes:
- bat-atsm-1: NOTRUN -> [SKIP][47] ([i915#6093]) +4 other tests skip
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@[email protected]
- bat-dg2-9: NOTRUN -> [SKIP][48] ([i915#5274])
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

* igt@kms_hdmi_inject@inject-audio:
- fi-apl-guc: NOTRUN -> [SKIP][49] ([fdo#109271]) +13 other tests skip
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-apl-guc/igt@[email protected]

* igt@kms_pipe_crc_basic@compare-crc-sanitycheck-xr24:
- bat-atsm-1: NOTRUN -> [SKIP][50] ([i915#1836]) +7 other tests skip
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@[email protected]

* igt@kms_pm_backlight@basic-brightness:
- fi-tgl-1115g4: NOTRUN -> [SKIP][51] ([i915#9812])
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-tgl-1115g4/igt@[email protected]
- bat-dg2-9: NOTRUN -> [SKIP][52] ([i915#5354])
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

* igt@kms_pm_rpm@basic-pci-d3-state:
- fi-ivb-3770: NOTRUN -> [SKIP][53] ([fdo#109271]) +18 other tests skip
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-ivb-3770/igt@[email protected]

* igt@kms_prop_blob@basic:
- bat-atsm-1: NOTRUN -> [SKIP][54] ([i915#7357])
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@[email protected]

* igt@kms_setmode@basic-clone-single-crtc:
- bat-rplp-1: NOTRUN -> [SKIP][55] ([i915#3555])
[55]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-rplp-1/igt@[email protected]
- bat-atsm-1: NOTRUN -> [SKIP][56] ([i915#6094])
[56]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@[email protected]
- bat-dg2-9: NOTRUN -> [SKIP][57] ([i915#3555])
[57]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]
- fi-tgl-1115g4: NOTRUN -> [SKIP][58] ([i915#3555])
[58]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-tgl-1115g4/igt@[email protected]

* igt@prime_vgem@basic-fence-flip:
- bat-atsm-1: NOTRUN -> [SKIP][59] ([fdo#109295] / [i915#6078])
[59]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@[email protected]
- bat-dg2-9: NOTRUN -> [SKIP][60] ([i915#3708])
[60]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

* igt@prime_vgem@basic-fence-mmap:
- bat-atsm-1: NOTRUN -> [SKIP][61] ([fdo#109295] / [i915#4077]) +1 other test skip
[61]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@[email protected]
- bat-dg2-9: NOTRUN -> [SKIP][62] ([i915#3708] / [i915#4077]) +1 other test skip
[62]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

* igt@prime_vgem@basic-read:
- bat-rplp-1: NOTRUN -> [SKIP][63] ([i915#3708]) +2 other tests skip
[63]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-rplp-1/igt@[email protected]

* igt@prime_vgem@basic-write:
- bat-atsm-1: NOTRUN -> [SKIP][64] ([fdo#109295]) +2 other tests skip
[64]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-atsm-1/igt@[email protected]
- bat-dg2-9: NOTRUN -> [SKIP][65] ([i915#3291] / [i915#3708]) +2 other tests skip
[65]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/bat-dg2-9/igt@[email protected]

#### Possible fixes ####

* igt@i915_selftest@live@execlists:
- fi-bsw-n3050: [ABORT][66] ([i915#9662]) -> [PASS][67]
[66]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14118/fi-bsw-n3050/igt@i915_selftest@[email protected]
[67]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/fi-bsw-n3050/igt@i915_selftest@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109285]: https://bugs.freedesktop.org/show_bug.cgi?id=109285
[fdo#109295]: https://bugs.freedesktop.org/show_bug.cgi?id=109295
[i915#1836]: https://gitlab.freedesktop.org/drm/intel/issues/1836
[i915#1849]: https://gitlab.freedesktop.org/drm/intel/issues/1849
[i915#2190]: https://gitlab.freedesktop.org/drm/intel/issues/2190
[i915#3282]: https://gitlab.freedesktop.org/drm/intel/issues/3282
[i915#3291]: https://gitlab.freedesktop.org/drm/intel/issues/3291
[i915#3555]: https://gitlab.freedesktop.org/drm/intel/issues/3555
[i915#3708]: https://gitlab.freedesktop.org/drm/intel/issues/3708
[i915#3840]: https://gitlab.freedesktop.org/drm/intel/issues/3840
[i915#4077]: https://gitlab.freedesktop.org/drm/intel/issues/4077
[i915#4079]: https://gitlab.freedesktop.org/drm/intel/issues/4079
[i915#4083]: https://gitlab.freedesktop.org/drm/intel/issues/4083
[i915#4103]: https://gitlab.freedesktop.org/drm/intel/issues/4103
[i915#4212]: https://gitlab.freedesktop.org/drm/intel/issues/4212
[i915#4213]: https://gitlab.freedesktop.org/drm/intel/issues/4213
[i915#4215]: https://gitlab.freedesktop.org/drm/intel/issues/4215
[i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613
[i915#4817]: https://gitlab.freedesktop.org/drm/intel/issues/4817
[i915#5190]: https://gitlab.freedesktop.org/drm/intel/issues/5190
[i915#5274]: https://gitlab.freedesktop.org/drm/intel/issues/5274
[i915#5354]: https://gitlab.freedesktop.org/drm/intel/issues/5354
[i915#6077]: https://gitlab.freedesktop.org/drm/intel/issues/6077
[i915#6078]: https://gitlab.freedesktop.org/drm/intel/issues/6078
[i915#6093]: https://gitlab.freedesktop.org/drm/intel/issues/6093
[i915#6094]: https://gitlab.freedesktop.org/drm/intel/issues/6094
[i915#6621]: https://gitlab.freedesktop.org/drm/intel/issues/6621
[i915#6645]: https://gitlab.freedesktop.org/drm/intel/issues/6645
[i915#7357]: https://gitlab.freedesktop.org/drm/intel/issues/7357
[i915#7443]: https://gitlab.freedesktop.org/drm/intel/issues/7443
[i915#9318]: https://gitlab.freedesktop.org/drm/intel/issues/9318
[i915#9662]: https://gitlab.freedesktop.org/drm/intel/issues/9662
[i915#9673]: https://gitlab.freedesktop.org/drm/intel/issues/9673
[i915#9732]: https://gitlab.freedesktop.org/drm/intel/issues/9732
[i915#9812]: https://gitlab.freedesktop.org/drm/intel/issues/9812

Build changes
-------------

* Linux: CI_DRM_14118 -> Patchwork_128718v1

CI-20190529: 20190529
CI_DRM_14118: 962785f4613664f29663206aa3355dc292a252c0 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7671: 7671
Patchwork_128718v1: 962785f4613664f29663206aa3355dc292a252c0 @ git://anongit.freedesktop.org/gfx-ci/linux

### Linux commits

ab846cb8afd5 drm/amdgpu: use GTT only as fallback for VRAM|GTT 349553643f80 drm/ttm: improve idle/busy handling v3 f475b737207b drm/ttm: replace busy placement with flags v6 7355c0c635ed drm/ttm: return ENOSPC from ttm_bo_mem_space ee6d461c3570 drm/vmwgfx: remove vmw_vram_gmr_placement

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_128718v1/index.html

#20 lore raw
In reply to Christian König

Am 12.01.24 um 13:51 schrieb Christian König:

Quoted 1 line

Hi guys,

just a gentle ping on this.

Zack any more comments for the VMWGFX parts?

Thanks,
Christian.

Quoted 15 lines

same as the last time. Things I've changed:

Implemented the requirements from Zack to correctly fill in the busy placements for VMWGFX.

Renamed the placement flags to desired and fallback as suggested by Michel.

Rebased on drm-tip instead of drm-misc-next and fixed XE as well.

Please review and comment,
Christian.

maintainer Reviewed-by
#21 lore raw
Quoted 7 lines · Christian König

Am 12.01.24 um 13:51 schrieb Christian König:

Quoted 1 line

Hi guys,

just a gentle ping on this.

Zack any more comments for the VMWGFX parts?

The new vmwgfx code looks great, thanks a lot for implementing it! In fact the entire series looks good to me. For the series:

z