dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/6] drm/i915/ttm: fix sparse warning
@ 2023-01-30 10:12 Matthew Auld
  2023-01-30 10:12 ` [PATCH 2/6] drm/i915/ttm: audit remaining bo->resource Matthew Auld
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Matthew Auld @ 2023-01-30 10:12 UTC (permalink / raw)
  To: intel-gfx; +Cc: Christian König, kernel test robot, dri-devel

Sparse complains with:

drivers/gpu/drm/i915/gem/i915_gem_ttm.c:1066:21: sparse:
	expected restricted vm_fault_t [assigned] [usertype] ret
drivers/gpu/drm/i915/gem/i915_gem_ttm.c:1066:21: sparse: got int

Fixes: 516198d317d8 ("drm/i915: audit bo->resource usage v3")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Christian König <ckoenig.leichtzumerken@gmail.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
index 7420276827a5..4758f21c91e1 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
@@ -1067,11 +1067,12 @@ static vm_fault_t vm_fault_ttm(struct vm_fault *vmf)
 			.interruptible = true,
 			.no_wait_gpu = true, /* should be idle already */
 		};
+		int err;
 
 		GEM_BUG_ON(!bo->ttm || !(bo->ttm->page_flags & TTM_TT_FLAG_SWAPPED));
 
-		ret = ttm_bo_validate(bo, i915_ttm_sys_placement(), &ctx);
-		if (ret) {
+		err = ttm_bo_validate(bo, i915_ttm_sys_placement(), &ctx);
+		if (err) {
 			dma_resv_unlock(bo->base.resv);
 			return VM_FAULT_SIGBUS;
 		}
-- 
2.39.1


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

* [PATCH 2/6] drm/i915/ttm: audit remaining bo->resource
  2023-01-30 10:12 [PATCH 1/6] drm/i915/ttm: fix sparse warning Matthew Auld
@ 2023-01-30 10:12 ` Matthew Auld
  2023-01-30 11:00   ` [Intel-gfx] " Andrzej Hajda
  2023-01-30 10:12 ` [PATCH 3/6] drm/ttm: clear the ttm_tt when bo->resource is NULL Matthew Auld
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 10+ messages in thread
From: Matthew Auld @ 2023-01-30 10:12 UTC (permalink / raw)
  To: intel-gfx; +Cc: Christian König, dri-devel, Nirmoy Das

In the near future TTM will have NULL bo->resource when the object is
initially created, plus after calling into pipeline-gutting. Try to
handle the remaining cases. In practice NULL bo->resource should be
taken to mean swapped-out or purged object.

References: 516198d317d8 ("drm/i915: audit bo->resource usage v3")
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Christian König <ckoenig.leichtzumerken@gmail.com>
Cc: Nirmoy Das <nirmoy.das@intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c      | 12 +++++++++---
 drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c |  7 ++++++-
 drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c   |  7 +++++--
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
index 4758f21c91e1..4ba1d7862ff9 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
@@ -472,7 +472,7 @@ static int i915_ttm_shrink(struct drm_i915_gem_object *obj, unsigned int flags)
 	struct ttm_placement place = {};
 	int ret;
 
-	if (!bo->ttm || bo->resource->mem_type != TTM_PL_SYSTEM)
+	if (!bo->ttm || (bo->resource && bo->resource->mem_type != TTM_PL_SYSTEM))
 		return 0;
 
 	GEM_BUG_ON(!i915_tt->is_shmem);
@@ -511,7 +511,13 @@ static void i915_ttm_delete_mem_notify(struct ttm_buffer_object *bo)
 {
 	struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
 
-	if (bo->resource && !i915_ttm_is_ghost_object(bo)) {
+	/*
+	 * This gets called twice by ttm, so long as we have a ttm resource or
+	 * ttm_tt then we can still safely call this. Due to pipeline-gutting,
+	 * we maybe have NULL bo->resource, but in that case we should always
+	 * have a ttm alive (like if the pages are swapped out).
+	 */
+	if ((bo->resource || bo->ttm) && !i915_ttm_is_ghost_object(bo)) {
 		__i915_gem_object_pages_fini(obj);
 		i915_ttm_free_cached_io_rsgt(obj);
 	}
@@ -1198,7 +1204,7 @@ static void i915_ttm_unmap_virtual(struct drm_i915_gem_object *obj)
 
 	assert_object_held_shared(obj);
 
-	if (i915_ttm_cpu_maps_iomem(bo->resource)) {
+	if (bo->resource && i915_ttm_cpu_maps_iomem(bo->resource)) {
 		wakeref = intel_runtime_pm_get(&to_i915(obj->base.dev)->runtime_pm);
 
 		/* userfault_count is protected by obj lock and rpm wakeref. */
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c
index 76dd9e5e1a8b..72953ebadfd8 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c
@@ -83,7 +83,8 @@ void i915_ttm_adjust_domains_after_move(struct drm_i915_gem_object *obj)
 {
 	struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
 
-	if (i915_ttm_cpu_maps_iomem(bo->resource) || bo->ttm->caching != ttm_cached) {
+	if ((bo->resource && i915_ttm_cpu_maps_iomem(bo->resource)) ||
+	    bo->ttm->caching != ttm_cached) {
 		obj->write_domain = I915_GEM_DOMAIN_WC;
 		obj->read_domains = I915_GEM_DOMAIN_WC;
 	} else {
@@ -711,6 +712,10 @@ int i915_gem_obj_copy_ttm(struct drm_i915_gem_object *dst,
 
 	assert_object_held(dst);
 	assert_object_held(src);
+
+	if (GEM_WARN_ON(!src_bo->resource || !dst_bo->resource))
+		return -EINVAL;
+
 	i915_deps_init(&deps, GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
 
 	ret = dma_resv_reserve_fences(src_bo->base.resv, 1);
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c
index 7e67742bc65e..be44e7eed892 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c
@@ -53,7 +53,7 @@ static int i915_ttm_backup(struct i915_gem_apply_to_region *apply,
 	unsigned int flags;
 	int err = 0;
 
-	if (bo->resource->mem_type == I915_PL_SYSTEM || obj->ttm.backup)
+	if (!bo->resource || bo->resource->mem_type == I915_PL_SYSTEM || obj->ttm.backup)
 		return 0;
 
 	if (pm_apply->allow_gpu && i915_gem_object_evictable(obj))
@@ -187,7 +187,10 @@ static int i915_ttm_restore(struct i915_gem_apply_to_region *apply,
 		return err;
 
 	/* Content may have been swapped. */
-	err = ttm_tt_populate(backup_bo->bdev, backup_bo->ttm, &ctx);
+	if (!backup_bo->resource)
+		err = ttm_bo_validate(backup_bo, i915_ttm_sys_placement(), &ctx);
+	if (!err)
+		err = ttm_tt_populate(backup_bo->bdev, backup_bo->ttm, &ctx);
 	if (!err) {
 		err = i915_gem_obj_copy_ttm(obj, backup, pm_apply->allow_gpu,
 					    false);
-- 
2.39.1


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

* [PATCH 3/6] drm/ttm: clear the ttm_tt when bo->resource is NULL
  2023-01-30 10:12 [PATCH 1/6] drm/i915/ttm: fix sparse warning Matthew Auld
  2023-01-30 10:12 ` [PATCH 2/6] drm/i915/ttm: audit remaining bo->resource Matthew Auld
@ 2023-01-30 10:12 ` Matthew Auld
  2023-01-30 10:12 ` [PATCH 4/6] drm/ttm: stop allocating dummy resources during BO creation Matthew Auld
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Matthew Auld @ 2023-01-30 10:12 UTC (permalink / raw)
  To: intel-gfx; +Cc: Christian König, dri-devel

In the next few patches, when initially creating a ttm BO, the
bo->resource is NULL, and the driver is then expected to handle the
initial dummy move.  However, if this is created as a system resource
the first ttm_tt we create will always have the clear value set to
false. Previously the initial ttm_tt would be created in
ttm_bo_validate() with the clear parameter always set to true.

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Christian König <ckoenig.leichtzumerken@gmail.com>
Reviewed-by: Christian König <ckoenig.leichtzumerken@gmail.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 326a3d13a829..773080f48864 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -120,8 +120,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 	bool old_use_tt, new_use_tt;
 	int ret;
 
-	old_use_tt = bo->resource &&
-		ttm_manager_type(bdev, bo->resource->mem_type)->use_tt;
+	old_use_tt = !bo->resource || ttm_manager_type(bdev, bo->resource->mem_type)->use_tt;
 	new_use_tt = ttm_manager_type(bdev, mem->mem_type)->use_tt;
 
 	ttm_bo_unmap_virtual(bo);
-- 
2.39.1


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

* [PATCH 4/6] drm/ttm: stop allocating dummy resources during BO creation
  2023-01-30 10:12 [PATCH 1/6] drm/i915/ttm: fix sparse warning Matthew Auld
  2023-01-30 10:12 ` [PATCH 2/6] drm/i915/ttm: audit remaining bo->resource Matthew Auld
  2023-01-30 10:12 ` [PATCH 3/6] drm/ttm: clear the ttm_tt when bo->resource is NULL Matthew Auld
@ 2023-01-30 10:12 ` Matthew Auld
  2023-01-30 10:12 ` [PATCH 5/6] drm/ttm: stop allocating a dummy resource for pipelined gutting Matthew Auld
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Matthew Auld @ 2023-01-30 10:12 UTC (permalink / raw)
  To: intel-gfx; +Cc: Christian König, dri-devel

From: Christian König <christian.koenig@amd.com>

That should not be necessary any more when drivers should at least be
able to handle the move without a resource.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 773080f48864..169818b32be2 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -952,7 +952,6 @@ int ttm_bo_init_reserved(struct ttm_device *bdev, struct ttm_buffer_object *bo,
 			 struct sg_table *sg, struct dma_resv *resv,
 			 void (*destroy) (struct ttm_buffer_object *))
 {
-	static const struct ttm_place sys_mem = { .mem_type = TTM_PL_SYSTEM };
 	int ret;
 
 	kref_init(&bo->kref);
@@ -969,12 +968,6 @@ int ttm_bo_init_reserved(struct ttm_device *bdev, struct ttm_buffer_object *bo,
 		bo->base.resv = &bo->base._resv;
 	atomic_inc(&ttm_glob.bo_count);
 
-	ret = ttm_resource_alloc(bo, &sys_mem, &bo->resource);
-	if (unlikely(ret)) {
-		ttm_bo_put(bo);
-		return ret;
-	}
-
 	/*
 	 * For ttm_bo_type_device buffers, allocate
 	 * address space from the device.
-- 
2.39.1


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

* [PATCH 5/6] drm/ttm: stop allocating a dummy resource for pipelined gutting
  2023-01-30 10:12 [PATCH 1/6] drm/i915/ttm: fix sparse warning Matthew Auld
                   ` (2 preceding siblings ...)
  2023-01-30 10:12 ` [PATCH 4/6] drm/ttm: stop allocating dummy resources during BO creation Matthew Auld
@ 2023-01-30 10:12 ` Matthew Auld
  2023-01-30 10:12 ` [PATCH 6/6] drm/ttm: prevent moving of pinned BOs Matthew Auld
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Matthew Auld @ 2023-01-30 10:12 UTC (permalink / raw)
  To: intel-gfx; +Cc: Christian König, dri-devel

From: Christian König <christian.koenig@amd.com>

That should not be necessary any more when drivers should at least be
able to handle a move without a resource.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 7635d7d6b13b..d9d2b0903b22 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -704,30 +704,23 @@ EXPORT_SYMBOL(ttm_bo_move_sync_cleanup);
  */
 int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
 {
-	static const struct ttm_place sys_mem = { .mem_type = TTM_PL_SYSTEM };
 	struct ttm_buffer_object *ghost;
-	struct ttm_resource *sys_res;
 	struct ttm_tt *ttm;
 	int ret;
 
-	ret = ttm_resource_alloc(bo, &sys_mem, &sys_res);
-	if (ret)
-		return ret;
-
 	/* If already idle, no need for ghost object dance. */
 	if (dma_resv_test_signaled(bo->base.resv, DMA_RESV_USAGE_BOOKKEEP)) {
 		if (!bo->ttm) {
 			/* See comment below about clearing. */
 			ret = ttm_tt_create(bo, true);
 			if (ret)
-				goto error_free_sys_mem;
+				return ret;
 		} else {
 			ttm_tt_unpopulate(bo->bdev, bo->ttm);
 			if (bo->type == ttm_bo_type_device)
 				ttm_tt_mark_for_clear(bo->ttm);
 		}
 		ttm_resource_free(bo, &bo->resource);
-		ttm_bo_assign_mem(bo, sys_res);
 		return 0;
 	}
 
@@ -744,7 +737,7 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
 	ret = ttm_tt_create(bo, true);
 	swap(bo->ttm, ttm);
 	if (ret)
-		goto error_free_sys_mem;
+		return ret;
 
 	ret = ttm_buffer_object_transfer(bo, &ghost);
 	if (ret)
@@ -760,13 +753,9 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
 	dma_resv_unlock(&ghost->base._resv);
 	ttm_bo_put(ghost);
 	bo->ttm = ttm;
-	ttm_bo_assign_mem(bo, sys_res);
 	return 0;
 
 error_destroy_tt:
 	ttm_tt_destroy(bo->bdev, ttm);
-
-error_free_sys_mem:
-	ttm_resource_free(bo, &sys_res);
 	return ret;
 }
-- 
2.39.1


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

* [PATCH 6/6] drm/ttm: prevent moving of pinned BOs
  2023-01-30 10:12 [PATCH 1/6] drm/i915/ttm: fix sparse warning Matthew Auld
                   ` (3 preceding siblings ...)
  2023-01-30 10:12 ` [PATCH 5/6] drm/ttm: stop allocating a dummy resource for pipelined gutting Matthew Auld
@ 2023-01-30 10:12 ` Matthew Auld
  2023-01-30 10:51 ` [Intel-gfx] [PATCH 1/6] drm/i915/ttm: fix sparse warning Andrzej Hajda
  2023-02-01  7:28 ` Christian König
  6 siblings, 0 replies; 10+ messages in thread
From: Matthew Auld @ 2023-01-30 10:12 UTC (permalink / raw)
  To: intel-gfx; +Cc: Christian König, dri-devel

From: Christian König <christian.koenig@amd.com>

We have checks for this in the individual drivers move callback, but
it's probably better to generally forbid that on a higher level.

Also stops exporting ttm_resource_compat() since that's not necessary
any more after removing the extra checks in vmwgfx.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c |  4 ----
 drivers/gpu/drm/nouveau/nouveau_bo.c    |  3 ---
 drivers/gpu/drm/radeon/radeon_ttm.c     |  4 ----
 drivers/gpu/drm/ttm/ttm_bo.c            | 20 ++++++++++++--------
 drivers/gpu/drm/ttm/ttm_resource.c      |  1 -
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c      | 19 ++-----------------
 6 files changed, 14 insertions(+), 37 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index c5ef7f7bdc15..2cd081cbf706 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -466,11 +466,7 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
 			return r;
 	}
 
-	/* Can't move a pinned BO */
 	abo = ttm_to_amdgpu_bo(bo);
-	if (WARN_ON_ONCE(abo->tbo.pin_count > 0))
-		return -EINVAL;
-
 	adev = amdgpu_ttm_adev(bo->bdev);
 
 	if (!old_mem || (old_mem->mem_type == TTM_PL_SYSTEM &&
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 288eebc70a67..c2ec91cc845d 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1015,9 +1015,6 @@ nouveau_bo_move(struct ttm_buffer_object *bo, bool evict,
 	if (ret)
 		goto out_ntfy;
 
-	if (nvbo->bo.pin_count)
-		NV_WARN(drm, "Moving pinned object %p!\n", nvbo);
-
 	if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) {
 		ret = nouveau_bo_vm_bind(bo, new_reg, &new_tile);
 		if (ret)
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 1e8e287e113c..67075c85f847 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -211,11 +211,7 @@ static int radeon_bo_move(struct ttm_buffer_object *bo, bool evict,
 	if (r)
 		return r;
 
-	/* Can't move a pinned BO */
 	rbo = container_of(bo, struct radeon_bo, tbo);
-	if (WARN_ON_ONCE(rbo->tbo.pin_count > 0))
-		return -EINVAL;
-
 	rdev = radeon_get_rdev(bo->bdev);
 	if (old_mem->mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) {
 		ttm_bo_move_null(bo, new_mem);
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 169818b32be2..882c2fa346f3 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -893,14 +893,18 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
 	if (!placement->num_placement && !placement->num_busy_placement)
 		return ttm_bo_pipeline_gutting(bo);
 
-	/*
-	 * Check whether we need to move buffer.
-	 */
-	if (!bo->resource || !ttm_resource_compat(bo->resource, placement)) {
-		ret = ttm_bo_move_buffer(bo, placement, ctx);
-		if (ret)
-			return ret;
-	}
+	/* Check whether we need to move buffer. */
+	if (bo->resource && ttm_resource_compat(bo->resource, placement))
+		return 0;
+
+	/* Moving of pinned BOs is forbidden */
+	if (bo->pin_count)
+		return -EINVAL;
+
+	ret = ttm_bo_move_buffer(bo, placement, ctx);
+	if (ret)
+		return ret;
+
 	/*
 	 * We might need to add a TTM.
 	 */
diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index b8a826a24fb2..7333f7a87a2f 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -361,7 +361,6 @@ bool ttm_resource_compat(struct ttm_resource *res,
 
 	return false;
 }
-EXPORT_SYMBOL(ttm_resource_compat);
 
 void ttm_resource_set_bo(struct ttm_resource *res,
 			 struct ttm_buffer_object *bo)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
index aa1cd5126a32..9bf1f9d2f9b6 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
@@ -87,12 +87,7 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
 	if (unlikely(ret != 0))
 		goto err;
 
-	if (buf->base.pin_count > 0)
-		ret = ttm_resource_compat(bo->resource, placement)
-			? 0 : -EINVAL;
-	else
-		ret = ttm_bo_validate(bo, placement, &ctx);
-
+	ret = ttm_bo_validate(bo, placement, &ctx);
 	if (!ret)
 		vmw_bo_pin_reserved(buf, true);
 
@@ -128,12 +123,6 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
 	if (unlikely(ret != 0))
 		goto err;
 
-	if (buf->base.pin_count > 0) {
-		ret = ttm_resource_compat(bo->resource, &vmw_vram_gmr_placement)
-			? 0 : -EINVAL;
-		goto out_unreserve;
-	}
-
 	ret = ttm_bo_validate(bo, &vmw_vram_gmr_placement, &ctx);
 	if (likely(ret == 0) || ret == -ERESTARTSYS)
 		goto out_unreserve;
@@ -218,11 +207,7 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
 		(void) ttm_bo_validate(bo, &vmw_sys_placement, &ctx);
 	}
 
-	if (buf->base.pin_count > 0)
-		ret = ttm_resource_compat(bo->resource, &placement)
-			? 0 : -EINVAL;
-	else
-		ret = ttm_bo_validate(bo, &placement, &ctx);
+	ret = ttm_bo_validate(bo, &placement, &ctx);
 
 	/* For some reason we didn't end up at the start of vram */
 	WARN_ON(ret == 0 && bo->resource->start != 0);
-- 
2.39.1


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

* Re: [Intel-gfx] [PATCH 1/6] drm/i915/ttm: fix sparse warning
  2023-01-30 10:12 [PATCH 1/6] drm/i915/ttm: fix sparse warning Matthew Auld
                   ` (4 preceding siblings ...)
  2023-01-30 10:12 ` [PATCH 6/6] drm/ttm: prevent moving of pinned BOs Matthew Auld
@ 2023-01-30 10:51 ` Andrzej Hajda
  2023-02-01  7:28 ` Christian König
  6 siblings, 0 replies; 10+ messages in thread
From: Andrzej Hajda @ 2023-01-30 10:51 UTC (permalink / raw)
  To: Matthew Auld, intel-gfx; +Cc: Christian König, dri-devel

On 30.01.2023 11:12, Matthew Auld wrote:
> Sparse complains with:
> 
> drivers/gpu/drm/i915/gem/i915_gem_ttm.c:1066:21: sparse:
> 	expected restricted vm_fault_t [assigned] [usertype] ret
> drivers/gpu/drm/i915/gem/i915_gem_ttm.c:1066:21: sparse: got int
> 
> Fixes: 516198d317d8 ("drm/i915: audit bo->resource usage v3")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Christian König <ckoenig.leichtzumerken@gmail.com>

Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>

Regards
Andrzej
> ---
>   drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> index 7420276827a5..4758f21c91e1 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> @@ -1067,11 +1067,12 @@ static vm_fault_t vm_fault_ttm(struct vm_fault *vmf)
>   			.interruptible = true,
>   			.no_wait_gpu = true, /* should be idle already */
>   		};
> +		int err;
>   
>   		GEM_BUG_ON(!bo->ttm || !(bo->ttm->page_flags & TTM_TT_FLAG_SWAPPED));
>   
> -		ret = ttm_bo_validate(bo, i915_ttm_sys_placement(), &ctx);
> -		if (ret) {
> +		err = ttm_bo_validate(bo, i915_ttm_sys_placement(), &ctx);
> +		if (err) {
>   			dma_resv_unlock(bo->base.resv);
>   			return VM_FAULT_SIGBUS;
>   		}


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

* Re: [Intel-gfx] [PATCH 2/6] drm/i915/ttm: audit remaining bo->resource
  2023-01-30 10:12 ` [PATCH 2/6] drm/i915/ttm: audit remaining bo->resource Matthew Auld
@ 2023-01-30 11:00   ` Andrzej Hajda
  2023-01-30 11:40     ` Matthew Auld
  0 siblings, 1 reply; 10+ messages in thread
From: Andrzej Hajda @ 2023-01-30 11:00 UTC (permalink / raw)
  To: Matthew Auld, intel-gfx; +Cc: Christian König, dri-devel, Nirmoy Das

On 30.01.2023 11:12, Matthew Auld wrote:
> In the near future TTM will have NULL bo->resource when the object is
> initially created, plus after calling into pipeline-gutting. Try to
> handle the remaining cases. In practice NULL bo->resource should be
> taken to mean swapped-out or purged object.
> 
> References: 516198d317d8 ("drm/i915: audit bo->resource usage v3")
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Christian König <ckoenig.leichtzumerken@gmail.com>
> Cc: Nirmoy Das <nirmoy.das@intel.com>
> ---
>   drivers/gpu/drm/i915/gem/i915_gem_ttm.c      | 12 +++++++++---
>   drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c |  7 ++++++-
>   drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c   |  7 +++++--
>   3 files changed, 20 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> index 4758f21c91e1..4ba1d7862ff9 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> @@ -472,7 +472,7 @@ static int i915_ttm_shrink(struct drm_i915_gem_object *obj, unsigned int flags)
>   	struct ttm_placement place = {};
>   	int ret;
>   
> -	if (!bo->ttm || bo->resource->mem_type != TTM_PL_SYSTEM)
> +	if (!bo->ttm || (bo->resource && bo->resource->mem_type != TTM_PL_SYSTEM))
>   		return 0;
>   
>   	GEM_BUG_ON(!i915_tt->is_shmem);
> @@ -511,7 +511,13 @@ static void i915_ttm_delete_mem_notify(struct ttm_buffer_object *bo)
>   {
>   	struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
>   
> -	if (bo->resource && !i915_ttm_is_ghost_object(bo)) {
> +	/*
> +	 * This gets called twice by ttm, so long as we have a ttm resource or
> +	 * ttm_tt then we can still safely call this. Due to pipeline-gutting,
> +	 * we maybe have NULL bo->resource, but in that case we should always
> +	 * have a ttm alive (like if the pages are swapped out).
> +	 */
> +	if ((bo->resource || bo->ttm) && !i915_ttm_is_ghost_object(bo)) {
>   		__i915_gem_object_pages_fini(obj);
>   		i915_ttm_free_cached_io_rsgt(obj);
>   	}
> @@ -1198,7 +1204,7 @@ static void i915_ttm_unmap_virtual(struct drm_i915_gem_object *obj)
>   
>   	assert_object_held_shared(obj);
>   
> -	if (i915_ttm_cpu_maps_iomem(bo->resource)) {
> +	if (bo->resource && i915_ttm_cpu_maps_iomem(bo->resource)) {

I wonder if i915_ttm_cpu_maps_iomem couldn't handle null resource?


>   		wakeref = intel_runtime_pm_get(&to_i915(obj->base.dev)->runtime_pm);
>   
>   		/* userfault_count is protected by obj lock and rpm wakeref. */
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c
> index 76dd9e5e1a8b..72953ebadfd8 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c
> @@ -83,7 +83,8 @@ void i915_ttm_adjust_domains_after_move(struct drm_i915_gem_object *obj)
>   {
>   	struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
>   
> -	if (i915_ttm_cpu_maps_iomem(bo->resource) || bo->ttm->caching != ttm_cached) {
> +	if ((bo->resource && i915_ttm_cpu_maps_iomem(bo->resource)) ||
> +	    bo->ttm->caching != ttm_cached) {
>   		obj->write_domain = I915_GEM_DOMAIN_WC;
>   		obj->read_domains = I915_GEM_DOMAIN_WC;
>   	} else {
> @@ -711,6 +712,10 @@ int i915_gem_obj_copy_ttm(struct drm_i915_gem_object *dst,
>   
>   	assert_object_held(dst);
>   	assert_object_held(src);
> +
> +	if (GEM_WARN_ON(!src_bo->resource || !dst_bo->resource))
> +		return -EINVAL;
> +
>   	i915_deps_init(&deps, GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
>   
>   	ret = dma_resv_reserve_fences(src_bo->base.resv, 1);
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c
> index 7e67742bc65e..be44e7eed892 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c
> @@ -53,7 +53,7 @@ static int i915_ttm_backup(struct i915_gem_apply_to_region *apply,
>   	unsigned int flags;
>   	int err = 0;
>   
> -	if (bo->resource->mem_type == I915_PL_SYSTEM || obj->ttm.backup)
> +	if (!bo->resource || bo->resource->mem_type == I915_PL_SYSTEM || obj->ttm.backup)

!i915_ttm_cpu_maps_iomem ?

>   		return 0;
>   
>   	if (pm_apply->allow_gpu && i915_gem_object_evictable(obj))
> @@ -187,7 +187,10 @@ static int i915_ttm_restore(struct i915_gem_apply_to_region *apply,
>   		return err;
>   
>   	/* Content may have been swapped. */
> -	err = ttm_tt_populate(backup_bo->bdev, backup_bo->ttm, &ctx);
> +	if (!backup_bo->resource)
> +		err = ttm_bo_validate(backup_bo, i915_ttm_sys_placement(), &ctx);
> +	if (!err)
> +		err = ttm_tt_populate(backup_bo->bdev, backup_bo->ttm, &ctx);

Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>

Regards
Andrzej


>   	if (!err) {
>   		err = i915_gem_obj_copy_ttm(obj, backup, pm_apply->allow_gpu,
>   					    false);


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

* Re: [Intel-gfx] [PATCH 2/6] drm/i915/ttm: audit remaining bo->resource
  2023-01-30 11:00   ` [Intel-gfx] " Andrzej Hajda
@ 2023-01-30 11:40     ` Matthew Auld
  0 siblings, 0 replies; 10+ messages in thread
From: Matthew Auld @ 2023-01-30 11:40 UTC (permalink / raw)
  To: Andrzej Hajda
  Cc: Christian König, intel-gfx, Matthew Auld, dri-devel, Nirmoy Das

On Mon, 30 Jan 2023 at 11:00, Andrzej Hajda <andrzej.hajda@intel.com> wrote:
>
> On 30.01.2023 11:12, Matthew Auld wrote:
> > In the near future TTM will have NULL bo->resource when the object is
> > initially created, plus after calling into pipeline-gutting. Try to
> > handle the remaining cases. In practice NULL bo->resource should be
> > taken to mean swapped-out or purged object.
> >
> > References: 516198d317d8 ("drm/i915: audit bo->resource usage v3")
> > Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> > Cc: Christian König <ckoenig.leichtzumerken@gmail.com>
> > Cc: Nirmoy Das <nirmoy.das@intel.com>
> > ---
> >   drivers/gpu/drm/i915/gem/i915_gem_ttm.c      | 12 +++++++++---
> >   drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c |  7 ++++++-
> >   drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c   |  7 +++++--
> >   3 files changed, 20 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> > index 4758f21c91e1..4ba1d7862ff9 100644
> > --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> > +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> > @@ -472,7 +472,7 @@ static int i915_ttm_shrink(struct drm_i915_gem_object *obj, unsigned int flags)
> >       struct ttm_placement place = {};
> >       int ret;
> >
> > -     if (!bo->ttm || bo->resource->mem_type != TTM_PL_SYSTEM)
> > +     if (!bo->ttm || (bo->resource && bo->resource->mem_type != TTM_PL_SYSTEM))
> >               return 0;
> >
> >       GEM_BUG_ON(!i915_tt->is_shmem);
> > @@ -511,7 +511,13 @@ static void i915_ttm_delete_mem_notify(struct ttm_buffer_object *bo)
> >   {
> >       struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
> >
> > -     if (bo->resource && !i915_ttm_is_ghost_object(bo)) {
> > +     /*
> > +      * This gets called twice by ttm, so long as we have a ttm resource or
> > +      * ttm_tt then we can still safely call this. Due to pipeline-gutting,
> > +      * we maybe have NULL bo->resource, but in that case we should always
> > +      * have a ttm alive (like if the pages are swapped out).
> > +      */
> > +     if ((bo->resource || bo->ttm) && !i915_ttm_is_ghost_object(bo)) {
> >               __i915_gem_object_pages_fini(obj);
> >               i915_ttm_free_cached_io_rsgt(obj);
> >       }
> > @@ -1198,7 +1204,7 @@ static void i915_ttm_unmap_virtual(struct drm_i915_gem_object *obj)
> >
> >       assert_object_held_shared(obj);
> >
> > -     if (i915_ttm_cpu_maps_iomem(bo->resource)) {
> > +     if (bo->resource && i915_ttm_cpu_maps_iomem(bo->resource)) {
>
> I wonder if i915_ttm_cpu_maps_iomem couldn't handle null resource?

Yeah, seems reasonable to me.

>
>
> >               wakeref = intel_runtime_pm_get(&to_i915(obj->base.dev)->runtime_pm);
> >
> >               /* userfault_count is protected by obj lock and rpm wakeref. */
> > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c
> > index 76dd9e5e1a8b..72953ebadfd8 100644
> > --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c
> > +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c
> > @@ -83,7 +83,8 @@ void i915_ttm_adjust_domains_after_move(struct drm_i915_gem_object *obj)
> >   {
> >       struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
> >
> > -     if (i915_ttm_cpu_maps_iomem(bo->resource) || bo->ttm->caching != ttm_cached) {
> > +     if ((bo->resource && i915_ttm_cpu_maps_iomem(bo->resource)) ||
> > +         bo->ttm->caching != ttm_cached) {
> >               obj->write_domain = I915_GEM_DOMAIN_WC;
> >               obj->read_domains = I915_GEM_DOMAIN_WC;
> >       } else {
> > @@ -711,6 +712,10 @@ int i915_gem_obj_copy_ttm(struct drm_i915_gem_object *dst,
> >
> >       assert_object_held(dst);
> >       assert_object_held(src);
> > +
> > +     if (GEM_WARN_ON(!src_bo->resource || !dst_bo->resource))
> > +             return -EINVAL;
> > +
> >       i915_deps_init(&deps, GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
> >
> >       ret = dma_resv_reserve_fences(src_bo->base.resv, 1);
> > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c
> > index 7e67742bc65e..be44e7eed892 100644
> > --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c
> > +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c
> > @@ -53,7 +53,7 @@ static int i915_ttm_backup(struct i915_gem_apply_to_region *apply,
> >       unsigned int flags;
> >       int err = 0;
> >
> > -     if (bo->resource->mem_type == I915_PL_SYSTEM || obj->ttm.backup)
> > +     if (!bo->resource || bo->resource->mem_type == I915_PL_SYSTEM || obj->ttm.backup)
>
> !i915_ttm_cpu_maps_iomem ?
>
> >               return 0;
> >
> >       if (pm_apply->allow_gpu && i915_gem_object_evictable(obj))
> > @@ -187,7 +187,10 @@ static int i915_ttm_restore(struct i915_gem_apply_to_region *apply,
> >               return err;
> >
> >       /* Content may have been swapped. */
> > -     err = ttm_tt_populate(backup_bo->bdev, backup_bo->ttm, &ctx);
> > +     if (!backup_bo->resource)
> > +             err = ttm_bo_validate(backup_bo, i915_ttm_sys_placement(), &ctx);
> > +     if (!err)
> > +             err = ttm_tt_populate(backup_bo->bdev, backup_bo->ttm, &ctx);
>
> Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>
>
> Regards
> Andrzej
>
>
> >       if (!err) {
> >               err = i915_gem_obj_copy_ttm(obj, backup, pm_apply->allow_gpu,
> >                                           false);
>

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

* Re: [PATCH 1/6] drm/i915/ttm: fix sparse warning
  2023-01-30 10:12 [PATCH 1/6] drm/i915/ttm: fix sparse warning Matthew Auld
                   ` (5 preceding siblings ...)
  2023-01-30 10:51 ` [Intel-gfx] [PATCH 1/6] drm/i915/ttm: fix sparse warning Andrzej Hajda
@ 2023-02-01  7:28 ` Christian König
  6 siblings, 0 replies; 10+ messages in thread
From: Christian König @ 2023-02-01  7:28 UTC (permalink / raw)
  To: Matthew Auld, intel-gfx; +Cc: kernel test robot, dri-devel

Am 30.01.23 um 11:12 schrieb Matthew Auld:
> Sparse complains with:
>
> drivers/gpu/drm/i915/gem/i915_gem_ttm.c:1066:21: sparse:
> 	expected restricted vm_fault_t [assigned] [usertype] ret
> drivers/gpu/drm/i915/gem/i915_gem_ttm.c:1066:21: sparse: got int
>
> Fixes: 516198d317d8 ("drm/i915: audit bo->resource usage v3")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Christian König <ckoenig.leichtzumerken@gmail.com>

Acked-by: Christian König <christian.koenig@amd.com> for the i915 patches.

I'm on vacation this week. going to push this to drm-misc-next when I'm 
back unless someone is faster.

Thanks,
Christian.

> ---
>   drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> index 7420276827a5..4758f21c91e1 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> @@ -1067,11 +1067,12 @@ static vm_fault_t vm_fault_ttm(struct vm_fault *vmf)
>   			.interruptible = true,
>   			.no_wait_gpu = true, /* should be idle already */
>   		};
> +		int err;
>   
>   		GEM_BUG_ON(!bo->ttm || !(bo->ttm->page_flags & TTM_TT_FLAG_SWAPPED));
>   
> -		ret = ttm_bo_validate(bo, i915_ttm_sys_placement(), &ctx);
> -		if (ret) {
> +		err = ttm_bo_validate(bo, i915_ttm_sys_placement(), &ctx);
> +		if (err) {
>   			dma_resv_unlock(bo->base.resv);
>   			return VM_FAULT_SIGBUS;
>   		}


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

end of thread, other threads:[~2023-02-01  7:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-30 10:12 [PATCH 1/6] drm/i915/ttm: fix sparse warning Matthew Auld
2023-01-30 10:12 ` [PATCH 2/6] drm/i915/ttm: audit remaining bo->resource Matthew Auld
2023-01-30 11:00   ` [Intel-gfx] " Andrzej Hajda
2023-01-30 11:40     ` Matthew Auld
2023-01-30 10:12 ` [PATCH 3/6] drm/ttm: clear the ttm_tt when bo->resource is NULL Matthew Auld
2023-01-30 10:12 ` [PATCH 4/6] drm/ttm: stop allocating dummy resources during BO creation Matthew Auld
2023-01-30 10:12 ` [PATCH 5/6] drm/ttm: stop allocating a dummy resource for pipelined gutting Matthew Auld
2023-01-30 10:12 ` [PATCH 6/6] drm/ttm: prevent moving of pinned BOs Matthew Auld
2023-01-30 10:51 ` [Intel-gfx] [PATCH 1/6] drm/i915/ttm: fix sparse warning Andrzej Hajda
2023-02-01  7:28 ` Christian König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).