Skip to contentSkip to conversation

Prepare error capture for asynchronous migration

PATCH Superseded Thomas Hellström 4 participants 15 messages Oct 27, 2021 – Oct 28, 2021

Subsystems (2)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover Prepare error capture for asynchronous migration

This patch series prepares error capture for asynchronous migration, where the vma pages may not reflect the pages the GPU is currently executing from but may be several migrations ahead.

The first patch deals with refcounting sg-list so that they don't disappear under the capture code, which typically otherwise happens at put_pages() time.

The second patch introduces vma state snapshots that record the vma state at request submission time. It also updates the memory allocation mode to reflect that error capture may and will happen in the dma-fence signalling critical path, and finally takes additional measures to make sure that the capture list and request is not disappearing from under us while capturing. The latter may otherwise happen if a heartbeat triggered parallel capture is running during a manual reset which retires the request.

Finally the last patch is more of a POC patch and not strictly needed yet, but will be (or at least something very similar) soon for async unbinding. It will make sure that unbinding doesn't complete or signal completion before capture is done. Async reuse of memory can't happen until unbinding signals complete and without waiting for capture done, we might capture contents of reused memory.
Before the last patch the vma active is instead still keeping the vma alive, but that will not work with async unbinding anymore, and also it is still not clear how we guarantee keeping the vma alive long enough to even grab an active reference during capture.

v2: Mostly Fixes for selftests and rebinding. See patch 3.

Thomas Hellström (3):
drm/i915: Introduce refcounted sg-tables
drm/i915: Update error capture code to avoid using the current vma
state
drm/i915: Initial introduction of vma resources

 drivers/gpu/drm/i915/Makefile                 |   1 +
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    | 137 +++++++++---
 drivers/gpu/drm/i915/gem/i915_gem_object.h    |   4 +-
 .../gpu/drm/i915/gem/i915_gem_object_types.h  |   3 +-
 drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  16 +-
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c       | 188 +++++++++-------
 drivers/gpu/drm/i915/gt/intel_engine_cs.c     |   8 +-
 .../drm/i915/gt/intel_execlists_submission.c  |   2 +-
 drivers/gpu/drm/i915/i915_gpu_error.c         | 180 +++++++++++-----
 drivers/gpu/drm/i915/i915_request.c           |  63 ++++--
 drivers/gpu/drm/i915/i915_request.h           |  18 +-
 drivers/gpu/drm/i915/i915_scatterlist.c       |  62 ++++--
 drivers/gpu/drm/i915/i915_scatterlist.h       |  76 ++++++-
 drivers/gpu/drm/i915/i915_vma.c               | 201 +++++++++++++++++-
 drivers/gpu/drm/i915/i915_vma.h               |  20 +-
 drivers/gpu/drm/i915/i915_vma_snapshot.c      | 131 ++++++++++++
 drivers/gpu/drm/i915/i915_vma_snapshot.h      | 112 ++++++++++
 drivers/gpu/drm/i915/i915_vma_types.h         |   5 +
 drivers/gpu/drm/i915/intel_region_ttm.c       |  15 +-
 drivers/gpu/drm/i915/intel_region_ttm.h       |   5 +-
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c |  99 +++++----
 drivers/gpu/drm/i915/selftests/mock_region.c  |  12 +-
 22 files changed, 1093 insertions(+), 265 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_vma_snapshot.c
 create mode 100644 drivers/gpu/drm/i915/i915_vma_snapshot.h
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/3 drm/i915: Introduce refcounted sg-tables

As we start to introduce asynchronous failsafe object migration, where we update the object state and then submit asynchronous commands we need to record what memory resources are actually used by various part of the command stream. Initially for three purposes:

1) Error capture.
2) Asynchronous migration error recovery.
3) Asynchronous vma bind.

At the time where these happens, the object state may have been updated to be several migrations ahead and object sg-tables discarded.

In order to make it possible to keep sg-tables with memory resource information for these operations, introduce refcounted sg-tables that aren't freed until the last user is done with them.

The alternative would be to reference information sitting on the corresponding ttm_resources which typically have the same lifetime as these refcountes sg_tables, but that leads to other awkward constructs:
Due to the design direction chosen for ttm resource managers that would lead to diamond-style inheritance, the LMEM resources may sometimes be prematurely freed, and finally the subclassed struct ttm_resource would have to bleed into the asynchronous vma bind code.

---
 drivers/gpu/drm/i915/gem/i915_gem_object.h    |   4 +-
 .../gpu/drm/i915/gem/i915_gem_object_types.h  |   3 +-
 drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  16 +-
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c       | 188 +++++++++++-------
 drivers/gpu/drm/i915/i915_scatterlist.c       |  62 ++++--
 drivers/gpu/drm/i915/i915_scatterlist.h       |  76 ++++++-
 drivers/gpu/drm/i915/intel_region_ttm.c       |  15 +-
 drivers/gpu/drm/i915/intel_region_ttm.h       |   5 +-
 drivers/gpu/drm/i915/selftests/mock_region.c  |  12 +-
 9 files changed, 262 insertions(+), 119 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.h +2 -2
index a5479ac7a4ad..c5ab364d4311 100644
@@ -624,8 +624,8 @@ struct sg_table *shmem_alloc_st(struct drm_i915_private *i915,
 				size_t size, struct intel_memory_region *mr,
 				struct address_space *mapping,
 				unsigned int max_segment);
-void shmem_free_st(struct sg_table *st, struct address_space *mapping,
-		   bool dirty, bool backup);
+void shmem_free_st_table(struct sg_table *st, struct address_space *mapping,
+			 bool dirty, bool backup);
 void __shmem_writeback(size_t size, struct address_space *mapping);
 
 #ifdef CONFIG_MMU_NOTIFIER
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +2 -1
index a4b69a43b898..604ed5ad77f5 100644
@@ -544,6 +544,7 @@ struct drm_i915_gem_object {
 		 */
 		struct list_head region_link;
 
+		struct i915_refct_sgt *rsgt;
 		struct sg_table *pages;
 		void *mapping;
 
@@ -597,7 +598,7 @@ struct drm_i915_gem_object {
 	} mm;
 
 	struct {
-		struct sg_table *cached_io_st;
+		struct i915_refct_sgt *cached_io_rsgt;
 		struct i915_gem_object_page_iter get_io_page;
 		struct drm_i915_gem_object *backup;
 		bool created:1;
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +9 -7
index 01f332d8dbde..67c6bee695c7 100644
@@ -25,8 +25,8 @@ static void check_release_pagevec(struct pagevec *pvec)
 	cond_resched();
 }
 
-void shmem_free_st(struct sg_table *st, struct address_space *mapping,
-		   bool dirty, bool backup)
+void shmem_free_st_table(struct sg_table *st, struct address_space *mapping,
+			 bool dirty, bool backup)
 {
 	struct sgt_iter sgt_iter;
 	struct pagevec pvec;
@@ -49,7 +49,6 @@ void shmem_free_st(struct sg_table *st, struct address_space *mapping,
 		check_release_pagevec(&pvec);
 
 	sg_free_table(st);
-	kfree(st);
 }
 
 struct sg_table *shmem_alloc_st(struct drm_i915_private *i915,
@@ -171,7 +170,8 @@ struct sg_table *shmem_alloc_st(struct drm_i915_private *i915,
 err_sg:
 	sg_mark_end(sg);
 	if (sg != st->sgl) {
-		shmem_free_st(st, mapping, false, false);
+		shmem_free_st_table(st, mapping, false, false);
+		kfree(st);
 	} else {
 		mapping_clear_unevictable(mapping);
 		sg_free_table(st);
@@ -254,7 +254,8 @@ static int shmem_get_pages(struct drm_i915_gem_object *obj)
 	return 0;
 
 err_pages:
-	shmem_free_st(st, mapping, false, false);
+	shmem_free_st_table(st, mapping, false, false);
+	kfree(st);
 	/*
 	 * shmemfs first checks if there is enough memory to allocate the page
 	 * and reports ENOSPC should there be insufficient, along with the usual
@@ -374,8 +375,9 @@ void i915_gem_object_put_pages_shmem(struct drm_i915_gem_object *obj, struct sg_
 	if (i915_gem_object_needs_bit17_swizzle(obj))
 		i915_gem_object_save_bit_17_swizzle(obj, pages);
 
-	shmem_free_st(pages, file_inode(obj->base.filp)->i_mapping,
-		      obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+	shmem_free_st_table(pages, file_inode(obj->base.filp)->i_mapping,
+			    obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+	kfree(pages);
 	obj->mm.dirty = false;
 }
 
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +113 -75

411 lines not on this page · raw message

drivers/gpu/drm/i915/i915_scatterlist.c +46 -16

126 lines not on this page · raw message

drivers/gpu/drm/i915/i915_scatterlist.h +72 -4

82 lines not on this page · raw message

drivers/gpu/drm/i915/intel_region_ttm.c +8 -7
index 98c7339bf8ba..2e901a27e259 100644
@@ -115,8 +115,8 @@ void intel_region_ttm_fini(struct intel_memory_region *mem)
 }
 
 /**
- * intel_region_ttm_resource_to_st - Convert an opaque TTM resource manager resource
- * to an sg_table.
+ * intel_region_ttm_resource_to_rsgt -
+ * Convert an opaque TTM resource manager resource to a refcounted sg_table.
  * @mem: The memory region.
  * @res: The resource manager resource obtained from the TTM resource manager.
  *
@@ -126,17 +126,18 @@ void intel_region_ttm_fini(struct intel_memory_region *mem)
  *
  * Return: A malloced sg_table on success, an error pointer on failure.
  */
-struct sg_table *intel_region_ttm_resource_to_st(struct intel_memory_region *mem,
-						 struct ttm_resource *res)
+struct i915_refct_sgt *
+intel_region_ttm_resource_to_rsgt(struct intel_memory_region *mem,
+				  struct ttm_resource *res)
 {
 	if (mem->is_range_manager) {
 		struct ttm_range_mgr_node *range_node =
 			to_ttm_range_mgr_node(res);
 
-		return i915_sg_from_mm_node(&range_node->mm_nodes[0],
-					    mem->region.start);
+		return i915_rsgt_from_mm_node(&range_node->mm_nodes[0],
+					      mem->region.start);
 	} else {
-		return i915_sg_from_buddy_resource(res, mem->region.start);
+		return i915_rsgt_from_buddy_resource(res, mem->region.start);
 	}
 }
 
drivers/gpu/drm/i915/intel_region_ttm.h +3 -2
index 6f44075920f2..7bbe2b46b504 100644
@@ -22,8 +22,9 @@ int intel_region_ttm_init(struct intel_memory_region *mem);
 
 void intel_region_ttm_fini(struct intel_memory_region *mem);
 
-struct sg_table *intel_region_ttm_resource_to_st(struct intel_memory_region *mem,
-						 struct ttm_resource *res);
+struct i915_refct_sgt *
+intel_region_ttm_resource_to_rsgt(struct intel_memory_region *mem,
+				  struct ttm_resource *res);
 
 void intel_region_ttm_resource_free(struct intel_memory_region *mem,
 				    struct ttm_resource *res);
drivers/gpu/drm/i915/selftests/mock_region.c +7 -5
index 75793008c4ef..7ec5037eaa58 100644
@@ -15,9 +15,9 @@
 static void mock_region_put_pages(struct drm_i915_gem_object *obj,
 				  struct sg_table *pages)
 {
+	i915_refct_sgt_put(obj->mm.rsgt);
+	obj->mm.rsgt = NULL;
 	intel_region_ttm_resource_free(obj->mm.region, obj->mm.res);
-	sg_free_table(pages);
-	kfree(pages);
 }
 
 static int mock_region_get_pages(struct drm_i915_gem_object *obj)
@@ -36,12 +36,14 @@ static int mock_region_get_pages(struct drm_i915_gem_object *obj)
 	if (IS_ERR(obj->mm.res))
 		return PTR_ERR(obj->mm.res);
 
-	pages = intel_region_ttm_resource_to_st(obj->mm.region, obj->mm.res);
-	if (IS_ERR(pages)) {
-		err = PTR_ERR(pages);
+	obj->mm.rsgt = intel_region_ttm_resource_to_rsgt(obj->mm.region,
+							 obj->mm.res);
+	if (IS_ERR(obj->mm.rsgt)) {
+		err = PTR_ERR(obj->mm.rsgt);
 		goto err_free_resource;
 	}
 
+	pages = &obj->mm.rsgt->table;
 	__i915_gem_object_set_pages(obj, pages, i915_sg_dma_sizes(pages->sgl));
 
 	return 0;
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH v2 1/3] drm/i915: Introduce refcounted sg-tables

Quoted 42 lines · Thomas Hellström

As we start to introduce asynchronous failsafe object migration, where we update the object state and then submit asynchronous commands we need to record what memory resources are actually used by various part of the command stream. Initially for three purposes:

1) Error capture.
2) Asynchronous migration error recovery.
3) Asynchronous vma bind.

At the time where these happens, the object state may have been updated to be several migrations ahead and object sg-tables discarded.

In order to make it possible to keep sg-tables with memory resource information for these operations, introduce refcounted sg-tables that aren't freed until the last user is done with them.

The alternative would be to reference information sitting on the corresponding ttm_resources which typically have the same lifetime as these refcountes sg_tables, but that leads to other awkward constructs:
Due to the design direction chosen for ttm resource managers that would lead to diamond-style inheritance, the LMEM resources may sometimes be prematurely freed, and finally the subclassed struct ttm_resource would have to bleed into the asynchronous vma bind code.

---
  drivers/gpu/drm/i915/gem/i915_gem_object.h    |   4 +-
  .../gpu/drm/i915/gem/i915_gem_object_types.h  |   3 +-
  drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  16 +-
  drivers/gpu/drm/i915/gem/i915_gem_ttm.c       | 188 +++++++++++-------
  drivers/gpu/drm/i915/i915_scatterlist.c       |  62 ++++--
  drivers/gpu/drm/i915/i915_scatterlist.h       |  76 ++++++-
  drivers/gpu/drm/i915/intel_region_ttm.c       |  15 +-
  drivers/gpu/drm/i915/intel_region_ttm.h       |   5 +-
  drivers/gpu/drm/i915/selftests/mock_region.c  |  12 +-
  9 files changed, 262 insertions(+), 119 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.h +0 -0
index a5479ac7a4ad..c5ab364d4311 100644

drivers/gpu/drm/i915/gem/i915_gem_object.h struct sg_table *shmem_alloc_st(struct drm_i915_private *i915, · line 628

Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_object.h +2 -2
@@ -624,8 +624,8 @@ struct sg_table *shmem_alloc_st(struct drm_i915_private *i915,
  				size_t size, struct intel_memory_region *mr,
  				struct address_space *mapping,
  				unsigned int max_segment);
-void shmem_free_st(struct sg_table *st, struct address_space *mapping,
-		   bool dirty, bool backup);
+void shmem_free_st_table(struct sg_table *st, struct address_space *mapping,
+			 bool dirty, bool backup);

s/st_table/sg_table/?

I thought st was shorthand for sg_table? Maybe shmem_sg_free_table?

Quoted 120 lines
drivers/gpu/drm/i915/gem/i915_gem_object.h +0 -0
  void __shmem_writeback(size_t size, struct address_space *mapping);
 
  #ifdef CONFIG_MMU_NOTIFIER
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +2 -1
index a4b69a43b898..604ed5ad77f5 100644
@@ -544,6 +544,7 @@ struct drm_i915_gem_object {
  		 */
  		struct list_head region_link;
 
+		struct i915_refct_sgt *rsgt;
  		struct sg_table *pages;
  		void *mapping;
 
@@ -597,7 +598,7 @@ struct drm_i915_gem_object {
  	} mm;
 
  	struct {
-		struct sg_table *cached_io_st;
+		struct i915_refct_sgt *cached_io_rsgt;
  		struct i915_gem_object_page_iter get_io_page;
  		struct drm_i915_gem_object *backup;
  		bool created:1;
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +9 -7
index 01f332d8dbde..67c6bee695c7 100644
@@ -25,8 +25,8 @@ static void check_release_pagevec(struct pagevec *pvec)
  	cond_resched();
  }
 
-void shmem_free_st(struct sg_table *st, struct address_space *mapping,
-		   bool dirty, bool backup)
+void shmem_free_st_table(struct sg_table *st, struct address_space *mapping,
+			 bool dirty, bool backup)
  {
  	struct sgt_iter sgt_iter;
  	struct pagevec pvec;
@@ -49,7 +49,6 @@ void shmem_free_st(struct sg_table *st, struct address_space *mapping,
  		check_release_pagevec(&pvec);
 
  	sg_free_table(st);
-	kfree(st);
  }
 
  struct sg_table *shmem_alloc_st(struct drm_i915_private *i915,
@@ -171,7 +170,8 @@ struct sg_table *shmem_alloc_st(struct drm_i915_private *i915,
  err_sg:
  	sg_mark_end(sg);
  	if (sg != st->sgl) {
-		shmem_free_st(st, mapping, false, false);
+		shmem_free_st_table(st, mapping, false, false);
+		kfree(st);
  	} else {
  		mapping_clear_unevictable(mapping);
  		sg_free_table(st);
@@ -254,7 +254,8 @@ static int shmem_get_pages(struct drm_i915_gem_object *obj)
  	return 0;
 
  err_pages:
-	shmem_free_st(st, mapping, false, false);
+	shmem_free_st_table(st, mapping, false, false);
+	kfree(st);
  	/*
  	 * shmemfs first checks if there is enough memory to allocate the page
  	 * and reports ENOSPC should there be insufficient, along with the usual
@@ -374,8 +375,9 @@ void i915_gem_object_put_pages_shmem(struct drm_i915_gem_object *obj, struct sg_
  	if (i915_gem_object_needs_bit17_swizzle(obj))
  		i915_gem_object_save_bit_17_swizzle(obj, pages);
 
-	shmem_free_st(pages, file_inode(obj->base.filp)->i_mapping,
-		      obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+	shmem_free_st_table(pages, file_inode(obj->base.filp)->i_mapping,
+			    obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+	kfree(pages);
  	obj->mm.dirty = false;
  }
 
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +5 -9
index 4fd2edb20dd9..6826e3859e18 100644
@@ -34,7 +34,7 @@
   * struct i915_ttm_tt - TTM page vector with additional private information
   * @ttm: The base TTM page vector.
   * @dev: The struct device used for dma mapping and unmapping.
- * @cached_st: The cached scatter-gather table.
+ * @cached_rsgt: The cached scatter-gather table.
   * @is_shmem: Set if using shmem.
   * @filp: The shmem file, if using shmem backend.
   *
@@ -47,7 +47,7 @@
  struct i915_ttm_tt {
  	struct ttm_tt ttm;
  	struct device *dev;
-	struct sg_table *cached_st;
+	struct i915_refct_sgt cached_rsgt;
 
  	bool is_shmem;
  	struct file *filp;
@@ -221,14 +221,10 @@ static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev,
  	if (IS_ERR(st))
  		return PTR_ERR(st);
 
-	err = dma_map_sg_attrs(i915_tt->dev,
-			       st->sgl, st->nents,
-			       DMA_BIDIRECTIONAL,
-			       DMA_ATTR_SKIP_CPU_SYNC);
-	if (err <= 0) {
-		err = -EINVAL;
+	err = dma_map_sgtable(i915_tt->dev, st, DMA_BIDIRECTIONAL,
+			      DMA_ATTR_SKIP_CPU_SYNC);
+	if (err)
  		goto err_free_st;
-	}
 
  	i = 0;
  	for_each_sgt_page(page, sgt_iter, st)

drivers/gpu/drm/i915/gem/i915_gem_ttm.c static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev, · line 237

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -1
@@ -237,11 +233,15 @@ static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev,
  	if (ttm->page_flags & TTM_TT_FLAG_SWAPPED)
  		ttm->page_flags &= ~TTM_TT_FLAG_SWAPPED;
 
-	i915_tt->cached_st = st;
+	i915_tt->cached_rsgt.table = *st;
+	kfree(st);

Will it work if the above just operates on the rsgt.table?

Quoted 12 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +4 -1
+
  	return 0;
 
  err_free_st:
-	shmem_free_st(st, filp->f_mapping, false, false);
+	shmem_free_st_table(st, filp->f_mapping, false, false);
+	kfree(st);
+
  	return err;
  }
 

drivers/gpu/drm/i915/gem/i915_gem_ttm.c static void i915_ttm_tt_shmem_unpopulate(struct ttm_tt *ttm) · line 254

Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -3
@@ -249,16 +249,29 @@ static void i915_ttm_tt_shmem_unpopulate(struct ttm_tt *ttm)
  {
  	struct i915_ttm_tt *i915_tt = container_of(ttm, typeof(*i915_tt), ttm);
  	bool backup = ttm->page_flags & TTM_TT_FLAG_SWAPPED;
+	struct sg_table *st = &i915_tt->cached_rsgt.table;
 
-	dma_unmap_sg(i915_tt->dev, i915_tt->cached_st->sgl,
-		     i915_tt->cached_st->nents,
-		     DMA_BIDIRECTIONAL);
+	if (st->sgl)

Can we ever hit this? I would have presumed not? Below also.

Quoted 335 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +88 -56
+		shmem_free_st_table(st,
+				    file_inode(i915_tt->filp)->i_mapping,
+				    backup, backup);
+}
 
-	shmem_free_st(fetch_and_zero(&i915_tt->cached_st),
-		      file_inode(i915_tt->filp)->i_mapping,
-		      backup, backup);
+static void i915_ttm_tt_release(struct kref *ref)
+{
+	struct i915_ttm_tt *i915_tt =
+		container_of(ref, typeof(*i915_tt), cached_rsgt.kref);
+	struct sg_table *st = &i915_tt->cached_rsgt.table;
+
+	GEM_WARN_ON(st->sgl);
+
+	kfree(i915_tt);
  }
 
+static const struct i915_refct_sgt_ops tt_rsgt_ops = {
+	.release = i915_ttm_tt_release
+};
+
  static struct ttm_tt *i915_ttm_tt_create(struct ttm_buffer_object *bo,
  					 uint32_t page_flags)
  {
@@ -287,6 +300,9 @@ static struct ttm_tt *i915_ttm_tt_create(struct ttm_buffer_object *bo,
  	if (ret)
  		goto err_free;
 
+	i915_refct_sgt_init_ops(&i915_tt->cached_rsgt, bo->base.size,
+				&tt_rsgt_ops);
+
  	i915_tt->dev = obj->base.dev->dev;
 
  	return &i915_tt->ttm;
@@ -311,17 +327,15 @@ static int i915_ttm_tt_populate(struct ttm_device *bdev,
  static void i915_ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
  {
  	struct i915_ttm_tt *i915_tt = container_of(ttm, typeof(*i915_tt), ttm);
+	struct sg_table *st = &i915_tt->cached_rsgt.table;
+
+	if (st->sgl)
+		dma_unmap_sgtable(i915_tt->dev, st, DMA_BIDIRECTIONAL, 0);
 
  	if (i915_tt->is_shmem) {
  		i915_ttm_tt_shmem_unpopulate(ttm);
  	} else {
-		if (i915_tt->cached_st) {
-			dma_unmap_sgtable(i915_tt->dev, i915_tt->cached_st,
-					  DMA_BIDIRECTIONAL, 0);
-			sg_free_table(i915_tt->cached_st);
-			kfree(i915_tt->cached_st);
-			i915_tt->cached_st = NULL;
-		}
+		sg_free_table(st);
  		ttm_pool_free(&bdev->pool, ttm);
  	}
  }
@@ -334,7 +348,7 @@ static void i915_ttm_tt_destroy(struct ttm_device *bdev, struct ttm_tt *ttm)
  		fput(i915_tt->filp);
 
  	ttm_tt_fini(ttm);
-	kfree(i915_tt);
+	i915_refct_sgt_put(&i915_tt->cached_rsgt);
  }
 
  static bool i915_ttm_eviction_valuable(struct ttm_buffer_object *bo,
@@ -376,12 +390,12 @@ static int i915_ttm_move_notify(struct ttm_buffer_object *bo)
  	return 0;
  }
 
-static void i915_ttm_free_cached_io_st(struct drm_i915_gem_object *obj)
+static void i915_ttm_free_cached_io_rsgt(struct drm_i915_gem_object *obj)
  {
  	struct radix_tree_iter iter;
  	void __rcu **slot;
 
-	if (!obj->ttm.cached_io_st)
+	if (!obj->ttm.cached_io_rsgt)
  		return;
 
  	rcu_read_lock();
@@ -389,9 +403,8 @@ static void i915_ttm_free_cached_io_st(struct drm_i915_gem_object *obj)
  		radix_tree_delete(&obj->ttm.get_io_page.radix, iter.index);
  	rcu_read_unlock();
 
-	sg_free_table(obj->ttm.cached_io_st);
-	kfree(obj->ttm.cached_io_st);
-	obj->ttm.cached_io_st = NULL;
+	i915_refct_sgt_put(obj->ttm.cached_io_rsgt);
+	obj->ttm.cached_io_rsgt = NULL;
  }
 
  static void
@@ -477,7 +490,7 @@ static int i915_ttm_purge(struct drm_i915_gem_object *obj)
  	obj->write_domain = 0;
  	obj->read_domains = 0;
  	i915_ttm_adjust_gem_after_move(obj);
-	i915_ttm_free_cached_io_st(obj);
+	i915_ttm_free_cached_io_rsgt(obj);
  	obj->mm.madv = __I915_MADV_PURGED;
  	return 0;
  }
@@ -532,7 +545,7 @@ static void i915_ttm_swap_notify(struct ttm_buffer_object *bo)
  	int ret = i915_ttm_move_notify(bo);
 
  	GEM_WARN_ON(ret);
-	GEM_WARN_ON(obj->ttm.cached_io_st);
+	GEM_WARN_ON(obj->ttm.cached_io_rsgt);
  	if (!ret && obj->mm.madv != I915_MADV_WILLNEED)
  		i915_ttm_purge(obj);
  }
@@ -543,7 +556,7 @@ static void i915_ttm_delete_mem_notify(struct ttm_buffer_object *bo)
 
  	if (likely(obj)) {
  		__i915_gem_object_pages_fini(obj);
-		i915_ttm_free_cached_io_st(obj);
+		i915_ttm_free_cached_io_rsgt(obj);
  	}
  }
 
@@ -563,40 +576,35 @@ i915_ttm_region(struct ttm_device *bdev, int ttm_mem_type)
  					  ttm_mem_type - I915_PL_LMEM0);
  }
 
-static struct sg_table *i915_ttm_tt_get_st(struct ttm_tt *ttm)
+static struct i915_refct_sgt *i915_ttm_tt_get_st(struct ttm_tt *ttm)
  {
  	struct i915_ttm_tt *i915_tt = container_of(ttm, typeof(*i915_tt), ttm);
  	struct sg_table *st;
  	int ret;
 
-	if (i915_tt->cached_st)
-		return i915_tt->cached_st;
-
-	st = kzalloc(sizeof(*st), GFP_KERNEL);
-	if (!st)
-		return ERR_PTR(-ENOMEM);
+	if (i915_tt->cached_rsgt.table.sgl)
+		return i915_refct_sgt_get(&i915_tt->cached_rsgt);
 
+	st = &i915_tt->cached_rsgt.table;
  	ret = sg_alloc_table_from_pages_segment(st,
  			ttm->pages, ttm->num_pages,
  			0, (unsigned long)ttm->num_pages << PAGE_SHIFT,
  			i915_sg_segment_size(), GFP_KERNEL);
  	if (ret) {
-		kfree(st);
+		st->sgl = NULL;
  		return ERR_PTR(ret);
  	}
 
  	ret = dma_map_sgtable(i915_tt->dev, st, DMA_BIDIRECTIONAL, 0);
  	if (ret) {
  		sg_free_table(st);
-		kfree(st);
  		return ERR_PTR(ret);
  	}
 
-	i915_tt->cached_st = st;
-	return st;
+	return i915_refct_sgt_get(&i915_tt->cached_rsgt);
  }
 
-static struct sg_table *
+static struct i915_refct_sgt *
  i915_ttm_resource_get_st(struct drm_i915_gem_object *obj,
  			 struct ttm_resource *res)
  {
@@ -610,7 +618,21 @@ i915_ttm_resource_get_st(struct drm_i915_gem_object *obj,
  	 * the resulting st. Might make sense for GGTT.
  	 */
  	GEM_WARN_ON(!cpu_maps_iomem(res));
-	return intel_region_ttm_resource_to_st(obj->mm.region, res);
+	if (bo->resource == res) {
+		if (!obj->ttm.cached_io_rsgt) {
+			struct i915_refct_sgt *rsgt;
+
+			rsgt = intel_region_ttm_resource_to_rsgt(obj->mm.region,
+								 res);
+			if (IS_ERR(rsgt))
+				return rsgt;
+
+			obj->ttm.cached_io_rsgt = rsgt;
+		}
+		return i915_refct_sgt_get(obj->ttm.cached_io_rsgt);
+	}
+
+	return intel_region_ttm_resource_to_rsgt(obj->mm.region, res);
  }
 
  static int i915_ttm_accel_move(struct ttm_buffer_object *bo,
@@ -621,10 +643,7 @@ static int i915_ttm_accel_move(struct ttm_buffer_object *bo,
  {
  	struct drm_i915_private *i915 = container_of(bo->bdev, typeof(*i915),
  						     bdev);
-	struct ttm_resource_manager *src_man =
-		ttm_manager_type(bo->bdev, bo->resource->mem_type);
  	struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
-	struct sg_table *src_st;
  	struct i915_request *rq;
  	struct ttm_tt *src_ttm = bo->ttm;
  	enum i915_cache_level src_level, dst_level;
@@ -650,17 +669,22 @@ static int i915_ttm_accel_move(struct ttm_buffer_object *bo,
  		}
  		intel_engine_pm_put(i915->gt.migrate.context->engine);
  	} else {
-		src_st = src_man->use_tt ? i915_ttm_tt_get_st(src_ttm) :
-			obj->ttm.cached_io_st;
+		struct i915_refct_sgt *src_rsgt =
+			i915_ttm_resource_get_st(obj, bo->resource);
+
+		if (IS_ERR(src_rsgt))
+			return PTR_ERR(src_rsgt);
 
  		src_level = i915_ttm_cache_level(i915, bo->resource, src_ttm);
  		intel_engine_pm_get(i915->gt.migrate.context->engine);
  		ret = intel_context_migrate_copy(i915->gt.migrate.context,
-						 NULL, src_st->sgl, src_level,
+						 NULL, src_rsgt->table.sgl,
+						 src_level,
  						 gpu_binds_iomem(bo->resource),
  						 dst_st->sgl, dst_level,
  						 gpu_binds_iomem(dst_mem),
  						 &rq);
+		i915_refct_sgt_put(src_rsgt);
  		if (!ret && rq) {
  			i915_request_wait(rq, 0, MAX_SCHEDULE_TIMEOUT);
  			i915_request_put(rq);
@@ -674,13 +698,14 @@ static int i915_ttm_accel_move(struct ttm_buffer_object *bo,
  static void __i915_ttm_move(struct ttm_buffer_object *bo, bool clear,
  			    struct ttm_resource *dst_mem,
  			    struct ttm_tt *dst_ttm,
-			    struct sg_table *dst_st,
+			    struct i915_refct_sgt *dst_rsgt,
  			    bool allow_accel)
  {
  	int ret = -EINVAL;
 
  	if (allow_accel)
-		ret = i915_ttm_accel_move(bo, clear, dst_mem, dst_ttm, dst_st);
+		ret = i915_ttm_accel_move(bo, clear, dst_mem, dst_ttm,
+					  &dst_rsgt->table);
  	if (ret) {
  		struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
  		struct intel_memory_region *dst_reg, *src_reg;
@@ -697,12 +722,13 @@ static void __i915_ttm_move(struct ttm_buffer_object *bo, bool clear,
  		dst_iter = !cpu_maps_iomem(dst_mem) ?
  			ttm_kmap_iter_tt_init(&_dst_iter.tt, dst_ttm) :
  			ttm_kmap_iter_iomap_init(&_dst_iter.io, &dst_reg->iomap,
-						 dst_st, dst_reg->region.start);
+						 &dst_rsgt->table,
+						 dst_reg->region.start);
 
  		src_iter = !cpu_maps_iomem(bo->resource) ?
  			ttm_kmap_iter_tt_init(&_src_iter.tt, bo->ttm) :
  			ttm_kmap_iter_iomap_init(&_src_iter.io, &src_reg->iomap,
-						 obj->ttm.cached_io_st,
+						 &obj->ttm.cached_io_rsgt->table,
  						 src_reg->region.start);
 
  		ttm_move_memcpy(clear, dst_mem->num_pages, dst_iter, src_iter);
@@ -718,7 +744,7 @@ static int i915_ttm_move(struct ttm_buffer_object *bo, bool evict,
  	struct ttm_resource_manager *dst_man =
  		ttm_manager_type(bo->bdev, dst_mem->mem_type);
  	struct ttm_tt *ttm = bo->ttm;
-	struct sg_table *dst_st;
+	struct i915_refct_sgt *dst_rsgt;
  	bool clear;
  	int ret;
 
@@ -744,22 +770,24 @@ static int i915_ttm_move(struct ttm_buffer_object *bo, bool evict,
  			return ret;
  	}
 
-	dst_st = i915_ttm_resource_get_st(obj, dst_mem);
-	if (IS_ERR(dst_st))
-		return PTR_ERR(dst_st);
+	dst_rsgt = i915_ttm_resource_get_st(obj, dst_mem);
+	if (IS_ERR(dst_rsgt))
+		return PTR_ERR(dst_rsgt);
 
  	clear = !cpu_maps_iomem(bo->resource) && (!ttm || !ttm_tt_is_populated(ttm));
  	if (!(clear && ttm && !(ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC)))
-		__i915_ttm_move(bo, clear, dst_mem, bo->ttm, dst_st, true);
+		__i915_ttm_move(bo, clear, dst_mem, bo->ttm, dst_rsgt, true);
 
  	ttm_bo_move_sync_cleanup(bo, dst_mem);
  	i915_ttm_adjust_domains_after_move(obj);
-	i915_ttm_free_cached_io_st(obj);
+	i915_ttm_free_cached_io_rsgt(obj);
 
  	if (gpu_binds_iomem(dst_mem) || cpu_maps_iomem(dst_mem)) {
-		obj->ttm.cached_io_st = dst_st;
-		obj->ttm.get_io_page.sg_pos = dst_st->sgl;
+		obj->ttm.cached_io_rsgt = dst_rsgt;
+		obj->ttm.get_io_page.sg_pos = dst_rsgt->table.sgl;
  		obj->ttm.get_io_page.sg_idx = 0;
+	} else {
+		i915_refct_sgt_put(dst_rsgt);
  	}
 
  	i915_ttm_adjust_lru(obj);
@@ -825,7 +853,6 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
  		.interruptible = true,
  		.no_wait_gpu = false,
  	};
-	struct sg_table *st;
  	int real_num_busy;
  	int ret;
 
@@ -862,12 +889,16 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
  	}
 
  	if (!i915_gem_object_has_pages(obj)) {
-		/* Object either has a page vector or is an iomem object */
-		st = bo->ttm ? i915_ttm_tt_get_st(bo->ttm) : obj->ttm.cached_io_st;
-		if (IS_ERR(st))
-			return PTR_ERR(st);
+		struct i915_refct_sgt *rsgt =
+			i915_ttm_resource_get_st(obj, bo->resource);
+
+		if (IS_ERR(rsgt))
+			return PTR_ERR(rsgt);
 
-		__i915_gem_object_set_pages(obj, st, i915_sg_dma_sizes(st->sgl));
+		GEM_BUG_ON(obj->mm.rsgt);
+		obj->mm.rsgt = rsgt;
+		__i915_gem_object_set_pages(obj, &rsgt->table,
+					    i915_sg_dma_sizes(rsgt->table.sgl));
  	}
 
  	i915_ttm_adjust_lru(obj);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c static void i915_ttm_put_pages(struct drm_i915_gem_object *obj, · line 979

Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +5 -0
@@ -941,6 +972,13 @@ static void i915_ttm_put_pages(struct drm_i915_gem_object *obj,
  	 * If the object is not destroyed next, The TTM eviction logic
  	 * and shrinkers will move it out if needed.
  	 */
+
+	if (obj->mm.rsgt) {
+		i915_refct_sgt_put(obj->mm.rsgt);
+		obj->mm.rsgt = NULL;
+	}

i915_refct_sgt_put(fetch_and_zero(&obj->mm.rsgt)) ?

drivers/gpu/drm/i915/gem/i915_gem_ttm.c static void i915_ttm_put_pages(struct drm_i915_gem_object *obj, · line 981

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -0
+
+	i915_ttm_adjust_lru(obj);

Unrelated change, or do I need to look closer?

Quoted 229 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +5 -5
  }
 
  static void i915_ttm_adjust_lru(struct drm_i915_gem_object *obj)
@@ -1278,7 +1316,7 @@ int i915_gem_obj_copy_ttm(struct drm_i915_gem_object *dst,
  	struct ttm_operation_ctx ctx = {
  		.interruptible = intr,
  	};
-	struct sg_table *dst_st;
+	struct i915_refct_sgt *dst_rsgt;
  	int ret;
 
  	assert_object_held(dst);
@@ -1293,11 +1331,11 @@ int i915_gem_obj_copy_ttm(struct drm_i915_gem_object *dst,
  	if (ret)
  		return ret;
 
-	dst_st = gpu_binds_iomem(dst_bo->resource) ?
-		dst->ttm.cached_io_st : i915_ttm_tt_get_st(dst_bo->ttm);
-
+	dst_rsgt = i915_ttm_resource_get_st(dst, dst_bo->resource);
  	__i915_ttm_move(src_bo, false, dst_bo->resource, dst_bo->ttm,
-			dst_st, allow_accel);
+			dst_rsgt, allow_accel);
+
+	i915_refct_sgt_put(dst_rsgt);
 
  	return 0;
  }
drivers/gpu/drm/i915/i915_scatterlist.c +46 -16
index 4a6712dca838..8a510ee5d1ad 100644
@@ -41,8 +41,32 @@ bool i915_sg_trim(struct sg_table *orig_st)
  	return true;
  }
 
+static void i915_refct_sgt_release(struct kref *ref)
+{
+	struct i915_refct_sgt *rsgt =
+		container_of(ref, typeof(*rsgt), kref);
+
+	sg_free_table(&rsgt->table);
+	kfree(rsgt);
+}
+
+static const struct i915_refct_sgt_ops rsgt_ops = {
+	.release = i915_refct_sgt_release
+};
+
+/**
+ * i915_refct_sgt_init - Initialize a struct i915_refct_sgt with default ops
+ * @rsgt: The struct i915_refct_sgt to initialize.
+ * size: The size of the underlying memory buffer.
+ */
+void i915_refct_sgt_init(struct i915_refct_sgt *rsgt, size_t size)
+{
+	i915_refct_sgt_init_ops(rsgt, size, &rsgt_ops);
+}
+
  /**
- * i915_sg_from_mm_node - Create an sg_table from a struct drm_mm_node
+ * i915_rsgt_from_mm_node - Create a refcounted sg_table from a struct
+ * drm_mm_node
   * @node: The drm_mm_node.
   * @region_start: An offset to add to the dma addresses of the sg list.
   *
@@ -50,25 +74,28 @@ bool i915_sg_trim(struct sg_table *orig_st)
   * taking a maximum segment length into account, splitting into segments
   * if necessary.
   *
- * Return: A pointer to a kmalloced struct sg_table on success, negative
+ * Return: A pointer to a kmalloced struct i915_refct_sgt on success, negative
   * error code cast to an error pointer on failure.
   */
-struct sg_table *i915_sg_from_mm_node(const struct drm_mm_node *node,
-				      u64 region_start)
+struct i915_refct_sgt *i915_rsgt_from_mm_node(const struct drm_mm_node *node,
+					      u64 region_start)
  {
  	const u64 max_segment = SZ_1G; /* Do we have a limit on this? */
  	u64 segment_pages = max_segment >> PAGE_SHIFT;
  	u64 block_size, offset, prev_end;
+	struct i915_refct_sgt *rsgt;
  	struct sg_table *st;
  	struct scatterlist *sg;
 
-	st = kmalloc(sizeof(*st), GFP_KERNEL);
-	if (!st)
+	rsgt = kmalloc(sizeof(*rsgt), GFP_KERNEL);
+	if (!rsgt)
  		return ERR_PTR(-ENOMEM);
 
+	i915_refct_sgt_init(rsgt, node->size << PAGE_SHIFT);
+	st = &rsgt->table;
  	if (sg_alloc_table(st, DIV_ROUND_UP(node->size, segment_pages),
  			   GFP_KERNEL)) {
-		kfree(st);
+		i915_refct_sgt_put(rsgt);
  		return ERR_PTR(-ENOMEM);
  	}
 
@@ -104,11 +131,11 @@ struct sg_table *i915_sg_from_mm_node(const struct drm_mm_node *node,
  	sg_mark_end(sg);
  	i915_sg_trim(st);
 
-	return st;
+	return rsgt;
  }
 
  /**
- * i915_sg_from_buddy_resource - Create an sg_table from a struct
+ * i915_rsgt_from_buddy_resource - Create a refcounted sg_table from a struct
   * i915_buddy_block list
   * @res: The struct i915_ttm_buddy_resource.
   * @region_start: An offset to add to the dma addresses of the sg list.
@@ -117,11 +144,11 @@ struct sg_table *i915_sg_from_mm_node(const struct drm_mm_node *node,
   * taking a maximum segment length into account, splitting into segments
   * if necessary.
   *
- * Return: A pointer to a kmalloced struct sg_table on success, negative
+ * Return: A pointer to a kmalloced struct i915_refct_sgts on success, negative
   * error code cast to an error pointer on failure.
   */
-struct sg_table *i915_sg_from_buddy_resource(struct ttm_resource *res,
-					     u64 region_start)
+struct i915_refct_sgt *i915_rsgt_from_buddy_resource(struct ttm_resource *res,
+						     u64 region_start)
  {
  	struct i915_ttm_buddy_resource *bman_res = to_ttm_buddy_resource(res);
  	const u64 size = res->num_pages << PAGE_SHIFT;
@@ -129,18 +156,21 @@ struct sg_table *i915_sg_from_buddy_resource(struct ttm_resource *res,
  	struct i915_buddy_mm *mm = bman_res->mm;
  	struct list_head *blocks = &bman_res->blocks;
  	struct i915_buddy_block *block;
+	struct i915_refct_sgt *rsgt;
  	struct scatterlist *sg;
  	struct sg_table *st;
  	resource_size_t prev_end;
 
  	GEM_BUG_ON(list_empty(blocks));
 
-	st = kmalloc(sizeof(*st), GFP_KERNEL);
-	if (!st)
+	rsgt = kmalloc(sizeof(*rsgt), GFP_KERNEL);
+	if (!rsgt)
  		return ERR_PTR(-ENOMEM);
 
+	i915_refct_sgt_init(rsgt, size);
+	st = &rsgt->table;
  	if (sg_alloc_table(st, res->num_pages, GFP_KERNEL)) {
-		kfree(st);
+		i915_refct_sgt_put(rsgt);
  		return ERR_PTR(-ENOMEM);
  	}
 
@@ -181,7 +211,7 @@ struct sg_table *i915_sg_from_buddy_resource(struct ttm_resource *res,
  	sg_mark_end(sg);
  	i915_sg_trim(st);
 
-	return st;
+	return rsgt;
  }
 
  #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
drivers/gpu/drm/i915/i915_scatterlist.h +55 -2
index b8bd5925b03f..321fd4a9f777 100644
@@ -144,10 +144,78 @@ static inline unsigned int i915_sg_segment_size(void)
 
  bool i915_sg_trim(struct sg_table *orig_st);
 
-struct sg_table *i915_sg_from_mm_node(const struct drm_mm_node *node,
-				      u64 region_start);
+/**
+ * struct i915_refct_sgt_ops - Operations structure for struct i915_refct_sgt
+ */
+struct i915_refct_sgt_ops {
+	/**
+	 * release() - Free the memory of the struct i915_refct_sgt
+	 * @ref: struct kref that is embedded in the struct i915_refct_sgt
+	 */
+	void (*release)(struct kref *ref);
+};
+
+/**
+ * struct i915_refct_sgt - A refcounted scatter-gather table
+ * @kref: struct kref for refcounting
+ * @table: struct sg_table holding the scatter-gather table itself. Note that
+ * @table->sgl = NULL can be used to determine whether a scatter-gather table
+ * is present or not.
+ * @size: The size in bytes of the underlying memory buffer
+ * @ops: The operations structure.
+ */
+struct i915_refct_sgt {
+	struct kref kref;
+	struct sg_table table;
+	size_t size;
+	const struct i915_refct_sgt_ops *ops;
+};
+
+/**
+ * i915_refct_sgt_put - Put a refcounted sg-table
+ * @rsgt the struct i915_refct_sgt to put.
+ */
+static inline void i915_refct_sgt_put(struct i915_refct_sgt *rsgt)
+{
+	if (rsgt)
+		kref_put(&rsgt->kref, rsgt->ops->release);
+}
+
+/**
+ * i915_refct_sgt_get - Get a refcounted sg-table
+ * @rsgt the struct i915_refct_sgt to get.
+ */
+static inline struct i915_refct_sgt *
+i915_refct_sgt_get(struct i915_refct_sgt *rsgt)
+{
+	kref_get(&rsgt->kref);
+	return rsgt;
+}
+
+/**
+ * i915_refct_sgt_init_ops - Initialize a refcounted sg-list with a custom
+ * operations structure
+ * @rsgt The struct i915_refct_sgt to initialize.
+ * @size: Size in bytes of the underlying memory buffer.
+ * @ops: A customized operations structure in case the refcounted sg-list
+ * is embedded into another structure.

drivers/gpu/drm/i915/i915_scatterlist.h static inline unsigned int i915_sg_segment_size(void) · line 211

Quoted 10 lines
drivers/gpu/drm/i915/i915_scatterlist.h +10 -0
+ */
+static inline void i915_refct_sgt_init_ops(struct i915_refct_sgt *rsgt,
+					   size_t size,
+					   const struct i915_refct_sgt_ops *ops)
+{
+	kref_init(&rsgt->kref);
+	rsgt->table.sgl = NULL;
+	rsgt->size = size;
+	rsgt->ops = ops;
+}

Could maybe make this __i915_refct_sgt_init(), since it inits more than just the ops?

Quoted 102 lines
drivers/gpu/drm/i915/i915_scatterlist.h +7 -2
+
+void i915_refct_sgt_init(struct i915_refct_sgt *rsgt, size_t size);
+
+struct i915_refct_sgt *i915_rsgt_from_mm_node(const struct drm_mm_node *node,
+					      u64 region_start);
 
-struct sg_table *i915_sg_from_buddy_resource(struct ttm_resource *res,
-					     u64 region_start);
+struct i915_refct_sgt *i915_rsgt_from_buddy_resource(struct ttm_resource *res,
+						     u64 region_start);
 
  #endif
drivers/gpu/drm/i915/intel_region_ttm.c +8 -7
index 98c7339bf8ba..2e901a27e259 100644
@@ -115,8 +115,8 @@ void intel_region_ttm_fini(struct intel_memory_region *mem)
  }
 
  /**
- * intel_region_ttm_resource_to_st - Convert an opaque TTM resource manager resource
- * to an sg_table.
+ * intel_region_ttm_resource_to_rsgt -
+ * Convert an opaque TTM resource manager resource to a refcounted sg_table.
   * @mem: The memory region.
   * @res: The resource manager resource obtained from the TTM resource manager.
   *
@@ -126,17 +126,18 @@ void intel_region_ttm_fini(struct intel_memory_region *mem)
   *
   * Return: A malloced sg_table on success, an error pointer on failure.
   */
-struct sg_table *intel_region_ttm_resource_to_st(struct intel_memory_region *mem,
-						 struct ttm_resource *res)
+struct i915_refct_sgt *
+intel_region_ttm_resource_to_rsgt(struct intel_memory_region *mem,
+				  struct ttm_resource *res)
  {
  	if (mem->is_range_manager) {
  		struct ttm_range_mgr_node *range_node =
  			to_ttm_range_mgr_node(res);
 
-		return i915_sg_from_mm_node(&range_node->mm_nodes[0],
-					    mem->region.start);
+		return i915_rsgt_from_mm_node(&range_node->mm_nodes[0],
+					      mem->region.start);
  	} else {
-		return i915_sg_from_buddy_resource(res, mem->region.start);
+		return i915_rsgt_from_buddy_resource(res, mem->region.start);
  	}
  }
 
drivers/gpu/drm/i915/intel_region_ttm.h +3 -2
index 6f44075920f2..7bbe2b46b504 100644
@@ -22,8 +22,9 @@ int intel_region_ttm_init(struct intel_memory_region *mem);
 
  void intel_region_ttm_fini(struct intel_memory_region *mem);
 
-struct sg_table *intel_region_ttm_resource_to_st(struct intel_memory_region *mem,
-						 struct ttm_resource *res);
+struct i915_refct_sgt *
+intel_region_ttm_resource_to_rsgt(struct intel_memory_region *mem,
+				  struct ttm_resource *res);
 
  void intel_region_ttm_resource_free(struct intel_memory_region *mem,
  				    struct ttm_resource *res);
drivers/gpu/drm/i915/selftests/mock_region.c +7 -5
index 75793008c4ef..7ec5037eaa58 100644
@@ -15,9 +15,9 @@
  static void mock_region_put_pages(struct drm_i915_gem_object *obj,
  				  struct sg_table *pages)
  {
+	i915_refct_sgt_put(obj->mm.rsgt);
+	obj->mm.rsgt = NULL;
  	intel_region_ttm_resource_free(obj->mm.region, obj->mm.res);
-	sg_free_table(pages);
-	kfree(pages);
  }
 
  static int mock_region_get_pages(struct drm_i915_gem_object *obj)
@@ -36,12 +36,14 @@ static int mock_region_get_pages(struct drm_i915_gem_object *obj)
  	if (IS_ERR(obj->mm.res))
  		return PTR_ERR(obj->mm.res);
 
-	pages = intel_region_ttm_resource_to_st(obj->mm.region, obj->mm.res);
-	if (IS_ERR(pages)) {
-		err = PTR_ERR(pages);
+	obj->mm.rsgt = intel_region_ttm_resource_to_rsgt(obj->mm.region,
+							 obj->mm.res);
+	if (IS_ERR(obj->mm.rsgt)) {
+		err = PTR_ERR(obj->mm.rsgt);
  		goto err_free_resource;
  	}
 
+	pages = &obj->mm.rsgt->table;
  	__i915_gem_object_set_pages(obj, pages, i915_sg_dma_sizes(pages->sgl));
 
  	return 0;
#3 lore raw

Re: [PATCH v2 1/3] drm/i915: Introduce refcounted sg-tables

Quoted 67 lines · Matthew Auld
Quoted 55 lines · Thomas Hellström

As we start to introduce asynchronous failsafe object migration, where we update the object state and then submit asynchronous commands we need to record what memory resources are actually used by various part of the command stream. Initially for three purposes:

1) Error capture.
2) Asynchronous migration error recovery.
3) Asynchronous vma bind.

At the time where these happens, the object state may have been updated
to be several migrations ahead and object sg-tables discarded.

In order to make it possible to keep sg-tables with memory resource information for these operations, introduce refcounted sg-tables that
aren't freed until the last user is done with them.

The alternative would be to reference information sitting on the corresponding ttm_resources which typically have the same lifetime as
these refcountes sg_tables, but that leads to other awkward constructs:
Due to the design direction chosen for ttm resource managers that would
lead to diamond-style inheritance, the LMEM resources may sometimes be
prematurely freed, and finally the subclassed struct ttm_resource would
have to bleed into the asynchronous vma bind code.

---
  drivers/gpu/drm/i915/gem/i915_gem_object.h    |   4 +- .../gpu/drm/i915/gem/i915_gem_object_types.h  |   3 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  16 +- drivers/gpu/drm/i915/gem/i915_gem_ttm.c       | 188 +++++++++++--
-----

  drivers/gpu/drm/i915/i915_scatterlist.c       |  62 ++++--
  drivers/gpu/drm/i915/i915_scatterlist.h       |  76 ++++++-
  drivers/gpu/drm/i915/intel_region_ttm.c       |  15 +-
  drivers/gpu/drm/i915/intel_region_ttm.h       |   5 +-
  drivers/gpu/drm/i915/selftests/mock_region.c  |  12 +-
  9 files changed, 262 insertions(+), 119 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.h +0 -0
index a5479ac7a4ad..c5ab364d4311 100644
@@ -624,8 +624,8 @@ struct sg_table *shmem_alloc_st(struct
 drm_i915_private *i915,

                                size_t size, struct intel_memory_region *mr,

Quoted 8 lines

                                struct address_space *mapping, unsigned int max_segment); -void shmem_free_st(struct sg_table *st, struct address_space *mapping,
-                  bool dirty, bool backup);
+void shmem_free_st_table(struct sg_table *st, struct address_space *mapping,
+                        bool dirty, bool backup);

s/st_table/sg_table/?

Quoted 1 line

I thought st was shorthand for sg_table? Maybe shmem_sg_free_table?

Yes the naming is indeed a bit unfortunate here. To be consistent with the core's sg_free_table(), I changed to shmem_sg_free_table() / shmem_sg_alloc_table.

Quoted 141 lines
Quoted 141 lines

  void __shmem_writeback(size_t size, struct address_space *mapping);

  #ifdef CONFIG_MMU_NOTIFIER

drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
index a4b69a43b898..604ed5ad77f5 100644
@@ -544,6 +544,7 @@ struct drm_i915_gem_object {
                  */
                 struct list_head region_link;


+               struct i915_refct_sgt *rsgt;
                struct sg_table *pages;
                void *mapping;

drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
@@ -597,7 +598,7 @@ struct drm_i915_gem_object {
         } mm;


        struct {
-               struct sg_table *cached_io_st;
+               struct i915_refct_sgt *cached_io_rsgt; struct i915_gem_object_page_iter get_io_page; struct drm_i915_gem_object *backup; bool created:1;

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
index 01f332d8dbde..67c6bee695c7 100644
@@ -25,8 +25,8 @@ static void check_release_pagevec(struct pagevec
 *pvec)
         cond_resched();
   }


-void shmem_free_st(struct sg_table *st, struct address_space *mapping,
-                  bool dirty, bool backup)
+void shmem_free_st_table(struct sg_table *st, struct address_space *mapping,
+                        bool dirty, bool backup)
  {
        struct sgt_iter sgt_iter;
        struct pagevec pvec;

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
@@ -49,7 +49,6 @@ void shmem_free_st(struct sg_table *st, struct
 address_space *mapping,
                 check_release_pagevec(&pvec);


        sg_free_table(st);
-       kfree(st);
  }

  struct sg_table *shmem_alloc_st(struct drm_i915_private *i915,

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
@@ -171,7 +170,8 @@ struct sg_table *shmem_alloc_st(struct
 drm_i915_private *i915,

  err_sg:
        sg_mark_end(sg);
        if (sg != st->sgl) {
-               shmem_free_st(st, mapping, false, false); +               shmem_free_st_table(st, mapping, false, false); +               kfree(st);
        } else {
                mapping_clear_unevictable(mapping); sg_free_table(st);

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
@@ -254,7 +254,8 @@ static int shmem_get_pages(struct
 drm_i915_gem_object *obj)
         return 0;


  err_pages:
-       shmem_free_st(st, mapping, false, false);
+       shmem_free_st_table(st, mapping, false, false); +       kfree(st);
        /*
         * shmemfs first checks if there is enough memory to allocate the page
         * and reports ENOSPC should there be insufficient, along with the usual

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
@@ -374,8 +375,9 @@ void i915_gem_object_put_pages_shmem(struct

drm_i915_gem_object *obj, struct sg_
        if (i915_gem_object_needs_bit17_swizzle(obj)) i915_gem_object_save_bit_17_swizzle(obj, pages);
-       shmem_free_st(pages, file_inode(obj->base.filp)->i_mapping, -                     obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+       shmem_free_st_table(pages, file_inode(obj->base.filp)-

Quoted 1 line

i_mapping,

+                           obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+       kfree(pages);
        obj->mm.dirty = false;
  }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
index 4fd2edb20dd9..6826e3859e18 100644
@@ -34,7 +34,7 @@
    * struct i915_ttm_tt - TTM page vector with additional private

information
   * @ttm: The base TTM page vector.
   * @dev: The struct device used for dma mapping and unmapping.
- * @cached_st: The cached scatter-gather table.
+ * @cached_rsgt: The cached scatter-gather table.
   * @is_shmem: Set if using shmem.
   * @filp: The shmem file, if using shmem backend.
   *

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -1
@@ -47,7 +47,7 @@
   struct i915_ttm_tt {
         struct ttm_tt ttm;
         struct device *dev;
-       struct sg_table *cached_st;
+       struct i915_refct_sgt cached_rsgt;


        bool is_shmem;
        struct file *filp;

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -221,14 +221,10 @@ static int i915_ttm_tt_shmem_populate(struct
 ttm_device *bdev,
         if (IS_ERR(st))
                 return PTR_ERR(st);


-       err = dma_map_sg_attrs(i915_tt->dev,
-                              st->sgl, st->nents,
-                              DMA_BIDIRECTIONAL,
-                              DMA_ATTR_SKIP_CPU_SYNC); -       if (err <= 0) {
-               err = -EINVAL;
+       err = dma_map_sgtable(i915_tt->dev, st, DMA_BIDIRECTIONAL, +                             DMA_ATTR_SKIP_CPU_SYNC); +       if (err)
                goto err_free_st;
-       }

        i = 0;
        for_each_sgt_page(page, sgt_iter, st)

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -237,11 +233,15 @@ static int i915_ttm_tt_shmem_populate(struct
 ttm_device *bdev,
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
         if (ttm->page_flags & TTM_TT_FLAG_SWAPPED)
                 ttm->page_flags &= ~TTM_TT_FLAG_SWAPPED;


-       i915_tt->cached_st = st;
+       i915_tt->cached_rsgt.table = *st;
+       kfree(st);

Will it work if the above just operates on the rsgt.table?

I'll change the shmem utility here to not allocate the struct sg_table and then we can operate on it directly.

Quoted 18 lines
Quoted 18 lines

+
        return 0;

  err_free_st:
-       shmem_free_st(st, filp->f_mapping, false, false); +       shmem_free_st_table(st, filp->f_mapping, false, false); +       kfree(st);
+
        return err;
  }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -249,16 +249,29 @@ static void
 i915_ttm_tt_shmem_unpopulate(struct ttm_tt *ttm)
   {
         struct i915_ttm_tt *i915_tt = container_of(ttm,
 typeof(*i915_tt), ttm);
         bool backup = ttm->page_flags & TTM_TT_FLAG_SWAPPED;
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -0
+       struct sg_table *st = &i915_tt->cached_rsgt.table;


-       dma_unmap_sg(i915_tt->dev, i915_tt->cached_st->sgl, -                    i915_tt->cached_st->nents,
-                    DMA_BIDIRECTIONAL);
+       if (st->sgl)

Can we ever hit this? I would have presumed not? Below also.

Yes, here's where we typically free the scatterlist.

Quoted 424 lines
Quoted 413 lines

+               shmem_free_st_table(st,
+                                   file_inode(i915_tt->filp)-

Quoted 1 line

i_mapping,

+                                   backup, backup); +}

-       shmem_free_st(fetch_and_zero(&i915_tt->cached_st), -                     file_inode(i915_tt->filp)->i_mapping, -                     backup, backup);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +4 -0
+static void i915_ttm_tt_release(struct kref *ref)
+{
+       struct i915_ttm_tt *i915_tt =
+               container_of(ref, typeof(*i915_tt),

cached_rsgt.kref);
+       struct sg_table *st = &i915_tt->cached_rsgt.table;

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +4 -0
+
+       GEM_WARN_ON(st->sgl);
+
+       kfree(i915_tt);

  }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +4 -0
+static const struct i915_refct_sgt_ops tt_rsgt_ops = {
+       .release = i915_ttm_tt_release
+};
+

  static struct ttm_tt *i915_ttm_tt_create(struct ttm_buffer_object *bo,
                                         uint32_t page_flags) {

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -287,6 +300,9 @@ static struct ttm_tt *i915_ttm_tt_create(struct
 ttm_buffer_object *bo,
         if (ret)
                 goto err_free;


+       i915_refct_sgt_init_ops(&i915_tt->cached_rsgt, bo-

Quoted 1 line

base.size,

+                               &tt_rsgt_ops);
+
        i915_tt->dev = obj->base.dev->dev;

        return &i915_tt->ttm;

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +4 -0
@@ -311,17 +327,15 @@ static int i915_ttm_tt_populate(struct
 ttm_device *bdev,
   static void i915_ttm_tt_unpopulate(struct ttm_device *bdev,
 struct ttm_tt *ttm)
   {
         struct i915_ttm_tt *i915_tt = container_of(ttm,
 typeof(*i915_tt), ttm);
+       struct sg_table *st = &i915_tt->cached_rsgt.table;
+
+       if (st->sgl)
+               dma_unmap_sgtable(i915_tt->dev, st,
 DMA_BIDIRECTIONAL, 0);


        if (i915_tt->is_shmem) { i915_ttm_tt_shmem_unpopulate(ttm);
        } else {
-               if (i915_tt->cached_st) {
-                       dma_unmap_sgtable(i915_tt->dev, i915_tt-

Quoted 1 line

cached_st,

-                                         DMA_BIDIRECTIONAL, 0); -                       sg_free_table(i915_tt->cached_st); -                       kfree(i915_tt->cached_st);
-                       i915_tt->cached_st = NULL;
-               }
+               sg_free_table(st); ttm_pool_free(&bdev->pool, ttm);
        }
  }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -334,7 +348,7 @@ static void i915_ttm_tt_destroy(struct
 ttm_device *bdev, struct ttm_tt *ttm)
                 fput(i915_tt->filp);


        ttm_tt_fini(ttm);
-       kfree(i915_tt);
+       i915_refct_sgt_put(&i915_tt->cached_rsgt);
  }

  static bool i915_ttm_eviction_valuable(struct ttm_buffer_object *bo,

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -376,12 +390,12 @@ static int i915_ttm_move_notify(struct
 ttm_buffer_object *bo)
         return 0;
   }


-static void i915_ttm_free_cached_io_st(struct drm_i915_gem_object *obj)
+static void i915_ttm_free_cached_io_rsgt(struct drm_i915_gem_object *obj)
  {
        struct radix_tree_iter iter;
        void __rcu **slot;

-       if (!obj->ttm.cached_io_st)
+       if (!obj->ttm.cached_io_rsgt)
                return;

        rcu_read_lock();

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -389,9 +403,8 @@ static void i915_ttm_free_cached_io_st(struct
 drm_i915_gem_object *obj)
                 radix_tree_delete(&obj->ttm.get_io_page.radix,
 iter.index);
         rcu_read_unlock();


-       sg_free_table(obj->ttm.cached_io_st); -       kfree(obj->ttm.cached_io_st);
-       obj->ttm.cached_io_st = NULL;
+       i915_refct_sgt_put(obj->ttm.cached_io_rsgt); +       obj->ttm.cached_io_rsgt = NULL;
  }

  static void

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -1
@@ -477,7 +490,7 @@ static int i915_ttm_purge(struct
 drm_i915_gem_object *obj)
         obj->write_domain = 0;
         obj->read_domains = 0;
         i915_ttm_adjust_gem_after_move(obj);
-       i915_ttm_free_cached_io_st(obj);
+       i915_ttm_free_cached_io_rsgt(obj);
         obj->mm.madv = __I915_MADV_PURGED;
         return 0;

  }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -532,7 +545,7 @@ static void i915_ttm_swap_notify(struct
 ttm_buffer_object *bo)
         int ret = i915_ttm_move_notify(bo);


        GEM_WARN_ON(ret);
-       GEM_WARN_ON(obj->ttm.cached_io_st);
+       GEM_WARN_ON(obj->ttm.cached_io_rsgt); if (!ret && obj->mm.madv != I915_MADV_WILLNEED) i915_ttm_purge(obj);
  }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -543,7 +556,7 @@ static void i915_ttm_delete_mem_notify(struct
 ttm_buffer_object *bo)


        if (likely(obj)) { __i915_gem_object_pages_fini(obj); -               i915_ttm_free_cached_io_st(obj); +               i915_ttm_free_cached_io_rsgt(obj); }
  }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -563,40 +576,35 @@ i915_ttm_region(struct ttm_device *bdev, int
 ttm_mem_type)

                                          ttm_mem_type - I915_PL_LMEM0);
  }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -1
-static struct sg_table *i915_ttm_tt_get_st(struct ttm_tt *ttm)
+static struct i915_refct_sgt *i915_ttm_tt_get_st(struct ttm_tt

*ttm)
  {
        struct i915_ttm_tt *i915_tt = container_of(ttm, typeof(*i915_tt), ttm);
        struct sg_table *st;
        int ret;

-       if (i915_tt->cached_st)
-               return i915_tt->cached_st;
-
-       st = kzalloc(sizeof(*st), GFP_KERNEL);
-       if (!st)
-               return ERR_PTR(-ENOMEM);
+       if (i915_tt->cached_rsgt.table.sgl)
+               return i915_refct_sgt_get(&i915_tt->cached_rsgt);
+       st = &i915_tt->cached_rsgt.table;
        ret = sg_alloc_table_from_pages_segment(st, ttm->pages, ttm->num_pages,
                        0, (unsigned long)ttm->num_pages << PAGE_SHIFT,
                        i915_sg_segment_size(), GFP_KERNEL); if (ret) {
-               kfree(st);
+               st->sgl = NULL;
                return ERR_PTR(ret);
        }

        ret = dma_map_sgtable(i915_tt->dev, st, DMA_BIDIRECTIONAL, 0);
        if (ret) {
                sg_free_table(st);
-               kfree(st);
                return ERR_PTR(ret);
        }

-       i915_tt->cached_st = st;
-       return st;
+       return i915_refct_sgt_get(&i915_tt->cached_rsgt); }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -1
-static struct sg_table *
+static struct i915_refct_sgt *

  i915_ttm_resource_get_st(struct drm_i915_gem_object *obj, struct ttm_resource *res) {

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +6 -1
@@ -610,7 +618,21 @@ i915_ttm_resource_get_st(struct
 drm_i915_gem_object *obj,
          * the resulting st. Might make sense for GGTT.
          */
         GEM_WARN_ON(!cpu_maps_iomem(res));
-       return intel_region_ttm_resource_to_st(obj->mm.region,
 res);
+       if (bo->resource == res) {
+               if (!obj->ttm.cached_io_rsgt) {
+                       struct i915_refct_sgt *rsgt;
+
+                       rsgt =
 intel_region_ttm_resource_to_rsgt(obj->mm.region,
+                                                               

res);
+                       if (IS_ERR(rsgt))
+                               return rsgt;

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +7 -0
+
+                       obj->ttm.cached_io_rsgt = rsgt;
+               }
+               return i915_refct_sgt_get(obj->ttm.cached_io_rsgt);
+       }
+
+       return intel_region_ttm_resource_to_rsgt(obj->mm.region,

res);
  }

  static int i915_ttm_accel_move(struct ttm_buffer_object *bo,

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -3
@@ -621,10 +643,7 @@ static int i915_ttm_accel_move(struct
 ttm_buffer_object *bo,
   {
         struct drm_i915_private *i915 = container_of(bo->bdev,
 typeof(*i915),
                                                      bdev);
-       struct ttm_resource_manager *src_man =
-               ttm_manager_type(bo->bdev, bo->resource->mem_type);
         struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
-       struct sg_table *src_st;
         struct i915_request *rq;

        struct ttm_tt *src_ttm = bo->ttm; enum i915_cache_level src_level, dst_level;

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -650,17 +669,22 @@ static int i915_ttm_accel_move(struct
 ttm_buffer_object *bo,
                 }

                intel_engine_pm_put(i915->gt.migrate.context-

Quoted 1 line

engine);

        } else {
-               src_st = src_man->use_tt ? i915_ttm_tt_get_st(src_ttm) :
-                       obj->ttm.cached_io_st;
+               struct i915_refct_sgt *src_rsgt = +                       i915_ttm_resource_get_st(obj, bo-

Quoted 1 line

resource);

+
+               if (IS_ERR(src_rsgt))
+                       return PTR_ERR(src_rsgt);
                src_level = i915_ttm_cache_level(i915, bo-

Quoted 1 line

resource, src_ttm);

                intel_engine_pm_get(i915->gt.migrate.context-

Quoted 1 line

engine);

                ret = intel_context_migrate_copy(i915-

Quoted 1 line

gt.migrate.context,

-                                                NULL, src_st->sgl, src_level,
+                                                NULL, src_rsgt-

Quoted 1 line

table.sgl,

+                                                src_level,
gpu_binds_iomem(bo->resource),
                                                 dst_st->sgl, dst_level,

gpu_binds_iomem(dst_mem),
                                                 &rq); +               i915_refct_sgt_put(src_rsgt);
                if (!ret && rq) { i915_request_wait(rq, 0, MAX_SCHEDULE_TIMEOUT);
                        i915_request_put(rq);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -674,13 +698,14 @@ static int i915_ttm_accel_move(struct
 ttm_buffer_object *bo,

  static void __i915_ttm_move(struct ttm_buffer_object *bo, bool clear,
                            struct ttm_resource *dst_mem, struct ttm_tt *dst_ttm,
-                           struct sg_table *dst_st,
+                           struct i915_refct_sgt *dst_rsgt, bool allow_accel)
  {
        int ret = -EINVAL;

        if (allow_accel)
-               ret = i915_ttm_accel_move(bo, clear, dst_mem, dst_ttm, dst_st);
+               ret = i915_ttm_accel_move(bo, clear, dst_mem, dst_ttm,
+                                         &dst_rsgt->table); if (ret) {
                struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
                struct intel_memory_region *dst_reg, *src_reg;

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -697,12 +722,13 @@ static void __i915_ttm_move(struct
 ttm_buffer_object *bo, bool clear,

                dst_iter = !cpu_maps_iomem(dst_mem) ? ttm_kmap_iter_tt_init(&_dst_iter.tt, dst_ttm) :
                        ttm_kmap_iter_iomap_init(&_dst_iter.io, &dst_reg->iomap,
-                                                dst_st, dst_reg-

Quoted 1 line

region.start);

+                                                &dst_rsgt->table, +                                                dst_reg-

Quoted 1 line

region.start);


                src_iter = !cpu_maps_iomem(bo->resource) ? ttm_kmap_iter_tt_init(&_src_iter.tt, bo-

Quoted 1 line

ttm) :

                        ttm_kmap_iter_iomap_init(&_src_iter.io, &src_reg->iomap,
-                                                obj-

Quoted 1 line

ttm.cached_io_st,

+                                                &obj-

Quoted 1 line

ttm.cached_io_rsgt->table,

                                                 src_reg-

Quoted 1 line

region.start);


                ttm_move_memcpy(clear, dst_mem->num_pages, dst_iter, src_iter);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -718,7 +744,7 @@ static int i915_ttm_move(struct
 ttm_buffer_object *bo, bool evict,

        struct ttm_resource_manager *dst_man = ttm_manager_type(bo->bdev, dst_mem->mem_type); struct ttm_tt *ttm = bo->ttm;
-       struct sg_table *dst_st;
+       struct i915_refct_sgt *dst_rsgt;
        bool clear;
        int ret;

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -744,22 +770,24 @@ static int i915_ttm_move(struct
 ttm_buffer_object *bo, bool evict,
                         return ret;
         }


-       dst_st = i915_ttm_resource_get_st(obj, dst_mem); -       if (IS_ERR(dst_st))
-               return PTR_ERR(dst_st);
+       dst_rsgt = i915_ttm_resource_get_st(obj, dst_mem); +       if (IS_ERR(dst_rsgt))
+               return PTR_ERR(dst_rsgt);

        clear = !cpu_maps_iomem(bo->resource) && (!ttm || !ttm_tt_is_populated(ttm));
        if (!(clear && ttm && !(ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC)))
-               __i915_ttm_move(bo, clear, dst_mem, bo->ttm, dst_st, true);
+               __i915_ttm_move(bo, clear, dst_mem, bo->ttm, dst_rsgt, true);

        ttm_bo_move_sync_cleanup(bo, dst_mem); i915_ttm_adjust_domains_after_move(obj);
-       i915_ttm_free_cached_io_st(obj);
+       i915_ttm_free_cached_io_rsgt(obj);

        if (gpu_binds_iomem(dst_mem) || cpu_maps_iomem(dst_mem)) { -               obj->ttm.cached_io_st = dst_st;
-               obj->ttm.get_io_page.sg_pos = dst_st->sgl; +               obj->ttm.cached_io_rsgt = dst_rsgt;
+               obj->ttm.get_io_page.sg_pos = dst_rsgt->table.sgl; obj->ttm.get_io_page.sg_idx = 0;
+       } else {
+               i915_refct_sgt_put(dst_rsgt);
        }

        i915_ttm_adjust_lru(obj);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -1
@@ -825,7 +853,6 @@ static int __i915_ttm_get_pages(struct
 drm_i915_gem_object *obj,
                 .interruptible = true,
                 .no_wait_gpu = false,
         };
-       struct sg_table *st;
         int real_num_busy;
         int ret;

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -862,12 +889,16 @@ static int __i915_ttm_get_pages(struct
 drm_i915_gem_object *obj,
         }


        if (!i915_gem_object_has_pages(obj)) {
-               /* Object either has a page vector or is an iomem object */
-               st = bo->ttm ? i915_ttm_tt_get_st(bo->ttm) : obj-

Quoted 1 line

ttm.cached_io_st;

-               if (IS_ERR(st))
-                       return PTR_ERR(st);
+               struct i915_refct_sgt *rsgt =
+                       i915_ttm_resource_get_st(obj, bo-

Quoted 1 line

resource);

+
+               if (IS_ERR(rsgt))
+                       return PTR_ERR(rsgt);

-               __i915_gem_object_set_pages(obj, st, i915_sg_dma_sizes(st->sgl));
+               GEM_BUG_ON(obj->mm.rsgt);
+               obj->mm.rsgt = rsgt;
+               __i915_gem_object_set_pages(obj, &rsgt->table, +                                           i915_sg_dma_sizes(rsgt-

Quoted 1 line

table.sgl));

        }

        i915_ttm_adjust_lru(obj);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -941,6 +972,13 @@ static void i915_ttm_put_pages(struct
 drm_i915_gem_object *obj,
          * If the object is not destroyed next, The TTM eviction
Quoted 8 lines

logic
         * and shrinkers will move it out if needed. */
+
+       if (obj->mm.rsgt) {
+               i915_refct_sgt_put(obj->mm.rsgt); +               obj->mm.rsgt = NULL;
+       }

i915_refct_sgt_put(fetch_and_zero(&obj->mm.rsgt)) ?

Quoted 4 lines
Quoted 2 lines

+
+       i915_ttm_adjust_lru(obj);

Unrelated change, or do I need to look closer?

No that's unrelated. Probably a rebase mistake. Will remove.

Quoted 276 lines
Quoted 276 lines

  }

  static void i915_ttm_adjust_lru(struct drm_i915_gem_object *obj)

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -1
@@ -1278,7 +1316,7 @@ int i915_gem_obj_copy_ttm(struct
 drm_i915_gem_object *dst,
         struct ttm_operation_ctx ctx = {
                 .interruptible = intr,
         };
-       struct sg_table *dst_st;
+       struct i915_refct_sgt *dst_rsgt;
         int ret;


        assert_object_held(dst);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -1293,11 +1331,11 @@ int i915_gem_obj_copy_ttm(struct
 drm_i915_gem_object *dst,
         if (ret)
                 return ret;


-       dst_st = gpu_binds_iomem(dst_bo->resource) ?
-               dst->ttm.cached_io_st : i915_ttm_tt_get_st(dst_bo-

Quoted 1 line

ttm);

-
+       dst_rsgt = i915_ttm_resource_get_st(dst, dst_bo->resource); __i915_ttm_move(src_bo, false, dst_bo->resource, dst_bo-

Quoted 1 line

ttm,

-                       dst_st, allow_accel);
+                       dst_rsgt, allow_accel);
+
+       i915_refct_sgt_put(dst_rsgt);

        return 0;
  }

drivers/gpu/drm/i915/i915_scatterlist.c +0 -0
index 4a6712dca838..8a510ee5d1ad 100644
@@ -41,8 +41,32 @@ bool i915_sg_trim(struct sg_table *orig_st)
         return true;
   }

drivers/gpu/drm/i915/i915_scatterlist.c +15 -0
+static void i915_refct_sgt_release(struct kref *ref)
+{
+       struct i915_refct_sgt *rsgt =
+               container_of(ref, typeof(*rsgt), kref);
+
+       sg_free_table(&rsgt->table);
+       kfree(rsgt);
+}
+
+static const struct i915_refct_sgt_ops rsgt_ops = {
+       .release = i915_refct_sgt_release
+};
+
+/**
+ * i915_refct_sgt_init - Initialize a struct i915_refct_sgt with

default ops
+ * @rsgt: The struct i915_refct_sgt to initialize.
+ * size: The size of the underlying memory buffer.
+ */

drivers/gpu/drm/i915/i915_scatterlist.c +5 -0
+void i915_refct_sgt_init(struct i915_refct_sgt *rsgt, size_t size)
+{
+       i915_refct_sgt_init_ops(rsgt, size, &rsgt_ops);
+}
+

  /**
- * i915_sg_from_mm_node - Create an sg_table from a struct drm_mm_node
+ * i915_rsgt_from_mm_node - Create a refcounted sg_table from a struct
+ * drm_mm_node
   * @node: The drm_mm_node.
   * @region_start: An offset to add to the dma addresses of the sg list.
   *

drivers/gpu/drm/i915/i915_scatterlist.c +0 -0
@@ -50,25 +74,28 @@ bool i915_sg_trim(struct sg_table *orig_st)
    * taking a maximum segment length into account, splitting into

segments
   * if necessary.
   *
- * Return: A pointer to a kmalloced struct sg_table on success, negative
+ * Return: A pointer to a kmalloced struct i915_refct_sgt on success, negative
   * error code cast to an error pointer on failure. */
-struct sg_table *i915_sg_from_mm_node(const struct drm_mm_node *node,
-                                     u64 region_start) +struct i915_refct_sgt *i915_rsgt_from_mm_node(const struct drm_mm_node *node,
+                                             u64 region_start) {
        const u64 max_segment = SZ_1G; /* Do we have a limit on this? */
        u64 segment_pages = max_segment >> PAGE_SHIFT; u64 block_size, offset, prev_end;
+       struct i915_refct_sgt *rsgt;
        struct sg_table *st;
        struct scatterlist *sg;

-       st = kmalloc(sizeof(*st), GFP_KERNEL);
-       if (!st)
+       rsgt = kmalloc(sizeof(*rsgt), GFP_KERNEL);
+       if (!rsgt)
                return ERR_PTR(-ENOMEM);

+       i915_refct_sgt_init(rsgt, node->size << PAGE_SHIFT); +       st = &rsgt->table;
        if (sg_alloc_table(st, DIV_ROUND_UP(node->size, segment_pages),
                           GFP_KERNEL)) {
-               kfree(st);
+               i915_refct_sgt_put(rsgt);
                return ERR_PTR(-ENOMEM);
        }

drivers/gpu/drm/i915/i915_scatterlist.c +0 -0
@@ -104,11 +131,11 @@ struct sg_table *i915_sg_from_mm_node(const
 struct drm_mm_node *node,
         sg_mark_end(sg);
         i915_sg_trim(st);


-       return st;
+       return rsgt;
  }

  /**
- * i915_sg_from_buddy_resource - Create an sg_table from a struct
+ * i915_rsgt_from_buddy_resource - Create a refcounted sg_table from a struct
   * i915_buddy_block list
   * @res: The struct i915_ttm_buddy_resource.
   * @region_start: An offset to add to the dma addresses of the sg list.

drivers/gpu/drm/i915/i915_scatterlist.c +0 -0
@@ -117,11 +144,11 @@ struct sg_table *i915_sg_from_mm_node(const
 struct drm_mm_node *node,
    * taking a maximum segment length into account, splitting into

segments
   * if necessary.
   *
- * Return: A pointer to a kmalloced struct sg_table on success, negative
+ * Return: A pointer to a kmalloced struct i915_refct_sgts on success, negative
   * error code cast to an error pointer on failure.
   */
-struct sg_table *i915_sg_from_buddy_resource(struct ttm_resource *res,
-                                            u64 region_start) +struct i915_refct_sgt *i915_rsgt_from_buddy_resource(struct ttm_resource *res,
+                                                    u64 region_start)
  {
        struct i915_ttm_buddy_resource *bman_res = to_ttm_buddy_resource(res);
        const u64 size = res->num_pages << PAGE_SHIFT;

drivers/gpu/drm/i915/i915_scatterlist.c +1 -0
@@ -129,18 +156,21 @@ struct sg_table
 *i915_sg_from_buddy_resource(struct ttm_resource *res,
         struct i915_buddy_mm *mm = bman_res->mm;
         struct list_head *blocks = &bman_res->blocks;
         struct i915_buddy_block *block;
+       struct i915_refct_sgt *rsgt;
         struct scatterlist *sg;
         struct sg_table *st;
         resource_size_t prev_end;


        GEM_BUG_ON(list_empty(blocks));

-       st = kmalloc(sizeof(*st), GFP_KERNEL);
-       if (!st)
+       rsgt = kmalloc(sizeof(*rsgt), GFP_KERNEL); +       if (!rsgt)
                return ERR_PTR(-ENOMEM);

+       i915_refct_sgt_init(rsgt, size);
+       st = &rsgt->table;
        if (sg_alloc_table(st, res->num_pages, GFP_KERNEL)) { -               kfree(st);
+               i915_refct_sgt_put(rsgt);
                return ERR_PTR(-ENOMEM);
        }

drivers/gpu/drm/i915/i915_scatterlist.c +0 -0
@@ -181,7 +211,7 @@ struct sg_table
 *i915_sg_from_buddy_resource(struct ttm_resource *res,
         sg_mark_end(sg);
         i915_sg_trim(st);


-       return st;
+       return rsgt;
  }

  #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)

drivers/gpu/drm/i915/i915_scatterlist.h +0 -0
index b8bd5925b03f..321fd4a9f777 100644
@@ -144,10 +144,78 @@ static inline unsigned int
 i915_sg_segment_size(void)


  bool i915_sg_trim(struct sg_table *orig_st);

-struct sg_table *i915_sg_from_mm_node(const struct drm_mm_node *node,
-                                     u64 region_start); +/**
+ * struct i915_refct_sgt_ops - Operations structure for struct i915_refct_sgt
+ */
+struct i915_refct_sgt_ops {
+       /**
+        * release() - Free the memory of the struct i915_refct_sgt +        * @ref: struct kref that is embedded in the struct i915_refct_sgt
+        */
+       void (*release)(struct kref *ref);

drivers/gpu/drm/i915/i915_scatterlist.h +6 -0
+};
+
+/**
+ * struct i915_refct_sgt - A refcounted scatter-gather table
+ * @kref: struct kref for refcounting
+ * @table: struct sg_table holding the scatter-gather table

itself. Note that
+ * @table->sgl = NULL can be used to determine whether a scatter- gather table
+ * is present or not.
+ * @size: The size in bytes of the underlying memory buffer
+ * @ops: The operations structure.
+ */

drivers/gpu/drm/i915/i915_scatterlist.h +30 -0
+struct i915_refct_sgt {
+       struct kref kref;
+       struct sg_table table;
+       size_t size;
+       const struct i915_refct_sgt_ops *ops;
+};
+
+/**
+ * i915_refct_sgt_put - Put a refcounted sg-table
+ * @rsgt the struct i915_refct_sgt to put.
+ */
+static inline void i915_refct_sgt_put(struct i915_refct_sgt *rsgt)
+{
+       if (rsgt)
+               kref_put(&rsgt->kref, rsgt->ops->release);
+}
+
+/**
+ * i915_refct_sgt_get - Get a refcounted sg-table
+ * @rsgt the struct i915_refct_sgt to get.
+ */
+static inline struct i915_refct_sgt *
+i915_refct_sgt_get(struct i915_refct_sgt *rsgt)
+{
+       kref_get(&rsgt->kref);
+       return rsgt;
+}
+
+/**
+ * i915_refct_sgt_init_ops - Initialize a refcounted sg-list with

a custom
+ * operations structure
+ * @rsgt The struct i915_refct_sgt to initialize.
+ * @size: Size in bytes of the underlying memory buffer.
+ * @ops: A customized operations structure in case the refcounted sg-list
+ * is embedded into another structure.
+ */
+static inline void i915_refct_sgt_init_ops(struct i915_refct_sgt *rsgt,
+                                          size_t size, +                                          const struct i915_refct_sgt_ops *ops)
+{
+       kref_init(&rsgt->kref);

Quoted 10 lines
Quoted 4 lines

+       rsgt->table.sgl = NULL;
+       rsgt->size = size;
+       rsgt->ops = ops;
+}

Could maybe make this __i915_refct_sgt_init(), since it inits more than
just the ops?

Will change.

Thanks,
Thomas

#4 lore raw

Re: [PATCH v2 1/3] drm/i915: Introduce refcounted sg-tables

Quoted 247 lines · Thomas Hellström
Quoted 67 lines · Matthew Auld
Quoted 61 lines · Thomas Hellström

As we start to introduce asynchronous failsafe object migration, where we update the object state and then submit asynchronous commands we need to record what memory resources are actually used by various part of the command stream. Initially for three purposes:

1) Error capture.
2) Asynchronous migration error recovery.
3) Asynchronous vma bind.

At the time where these happens, the object state may have been updated
to be several migrations ahead and object sg-tables discarded.

In order to make it possible to keep sg-tables with memory resource information for these operations, introduce refcounted sg-tables that
aren't freed until the last user is done with them.

The alternative would be to reference information sitting on the corresponding ttm_resources which typically have the same lifetime as
these refcountes sg_tables, but that leads to other awkward constructs:
Due to the design direction chosen for ttm resource managers that would
lead to diamond-style inheritance, the LMEM resources may sometimes be
prematurely freed, and finally the subclassed struct ttm_resource would
have to bleed into the asynchronous vma bind code.

---
   drivers/gpu/drm/i915/gem/i915_gem_object.h    |   4 +-
   .../gpu/drm/i915/gem/i915_gem_object_types.h  |   3 +-
   drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  16 +-
   drivers/gpu/drm/i915/gem/i915_gem_ttm.c       | 188 +++++++++++--
-----
   drivers/gpu/drm/i915/i915_scatterlist.c       |  62 ++++--
   drivers/gpu/drm/i915/i915_scatterlist.h       |  76 ++++++-
   drivers/gpu/drm/i915/intel_region_ttm.c       |  15 +-
   drivers/gpu/drm/i915/intel_region_ttm.h       |   5 +-
   drivers/gpu/drm/i915/selftests/mock_region.c  |  12 +-
   9 files changed, 262 insertions(+), 119 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.h +1 -2
index a5479ac7a4ad..c5ab364d4311 100644
@@ -624,8 +624,8 @@ struct sg_table *shmem_alloc_st(struct
 drm_i915_private *i915,
                                 size_t size, struct
 intel_memory_region *mr,
                                 struct address_space *mapping,
                                 unsigned int max_segment);
-void shmem_free_st(struct sg_table *st, struct address_space
 *mapping,
-                  bool dirty, bool backup);
+void shmem_free_st_table(struct sg_table *st, struct address_space
Quoted 2 lines

*mapping,
+                        bool dirty, bool backup);

s/st_table/sg_table/?

Quoted 1 line

I thought st was shorthand for sg_table? Maybe shmem_sg_free_table?

Yes the naming is indeed a bit unfortunate here. To be consistent with the core's sg_free_table(), I changed to shmem_sg_free_table() / shmem_sg_alloc_table.

Quoted 144 lines
Quoted 144 lines

  void __shmem_writeback(size_t size, struct address_space
*mapping);

  #ifdef CONFIG_MMU_NOTIFIER

drivers/gpu/drm/i915/gem/i915_gem_object_types.h +2 -1
index a4b69a43b898..604ed5ad77f5 100644
@@ -544,6 +544,7 @@ struct drm_i915_gem_object {
                  */
                 struct list_head region_link;
 
+               struct i915_refct_sgt *rsgt;
                 struct sg_table *pages;
                 void *mapping;
 
@@ -597,7 +598,7 @@ struct drm_i915_gem_object {
         } mm;
 
         struct {
-               struct sg_table *cached_io_st;
+               struct i915_refct_sgt *cached_io_rsgt;
                 struct i915_gem_object_page_iter get_io_page;
                 struct drm_i915_gem_object *backup;
                 bool created:1;
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +2 -2
index 01f332d8dbde..67c6bee695c7 100644
@@ -25,8 +25,8 @@ static void check_release_pagevec(struct pagevec
 *pvec)
         cond_resched();
   }
 
-void shmem_free_st(struct sg_table *st, struct address_space
 *mapping,
-                  bool dirty, bool backup)
+void shmem_free_st_table(struct sg_table *st, struct address_space
 *mapping,
+                        bool dirty, bool backup)

  {
        struct sgt_iter sgt_iter;
        struct pagevec pvec;

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -1
@@ -49,7 +49,6 @@ void shmem_free_st(struct sg_table *st, struct
 address_space *mapping,
                 check_release_pagevec(&pvec);
 
         sg_free_table(st);
-       kfree(st);
   }
 

  struct sg_table *shmem_alloc_st(struct drm_i915_private *i915,

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +2 -1
@@ -171,7 +170,8 @@ struct sg_table *shmem_alloc_st(struct
 drm_i915_private *i915,
   err_sg:
         sg_mark_end(sg);
         if (sg != st->sgl) {
-               shmem_free_st(st, mapping, false, false);
+               shmem_free_st_table(st, mapping, false, false);
+               kfree(st);
         } else {
                 mapping_clear_unevictable(mapping);

                sg_free_table(st);

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +2 -1
@@ -254,7 +254,8 @@ static int shmem_get_pages(struct
 drm_i915_gem_object *obj)
         return 0;
 
   err_pages:
-       shmem_free_st(st, mapping, false, false);
+       shmem_free_st_table(st, mapping, false, false);
+       kfree(st);
         /*
          * shmemfs first checks if there is enough memory to

allocate the page
         * and reports ENOSPC should there be insufficient, along
with the usual

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
@@ -374,8 +375,9 @@ void i915_gem_object_put_pages_shmem(struct

drm_i915_gem_object *obj, struct sg_
        if (i915_gem_object_needs_bit17_swizzle(obj)) i915_gem_object_save_bit_17_swizzle(obj, pages);

-       shmem_free_st(pages, file_inode(obj->base.filp)->i_mapping, -                     obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+       shmem_free_st_table(pages, file_inode(obj->base.filp)-

Quoted 1 line

i_mapping,

+                           obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+       kfree(pages);
        obj->mm.dirty = false;
  }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
index 4fd2edb20dd9..6826e3859e18 100644
@@ -34,7 +34,7 @@
    * struct i915_ttm_tt - TTM page vector with additional private

information
   * @ttm: The base TTM page vector.
   * @dev: The struct device used for dma mapping and unmapping.
- * @cached_st: The cached scatter-gather table.
+ * @cached_rsgt: The cached scatter-gather table.
   * @is_shmem: Set if using shmem.
   * @filp: The shmem file, if using shmem backend.
   *

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +4 -8
@@ -47,7 +47,7 @@
   struct i915_ttm_tt {
         struct ttm_tt ttm;
         struct device *dev;
-       struct sg_table *cached_st;
+       struct i915_refct_sgt cached_rsgt;
 
         bool is_shmem;
         struct file *filp;
@@ -221,14 +221,10 @@ static int i915_ttm_tt_shmem_populate(struct
 ttm_device *bdev,
         if (IS_ERR(st))
                 return PTR_ERR(st);
 
-       err = dma_map_sg_attrs(i915_tt->dev,
-                              st->sgl, st->nents,
-                              DMA_BIDIRECTIONAL,
-                              DMA_ATTR_SKIP_CPU_SYNC);
-       if (err <= 0) {
-               err = -EINVAL;
+       err = dma_map_sgtable(i915_tt->dev, st, DMA_BIDIRECTIONAL,
+                             DMA_ATTR_SKIP_CPU_SYNC);
+       if (err)
                 goto err_free_st;
-       }
 
         i = 0;

        for_each_sgt_page(page, sgt_iter, st)

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -237,11 +233,15 @@ static int i915_ttm_tt_shmem_populate(struct
 ttm_device *bdev,
         if (ttm->page_flags & TTM_TT_FLAG_SWAPPED)
                 ttm->page_flags &= ~TTM_TT_FLAG_SWAPPED;
 
Quoted 5 lines

drivers/gpu/drm/i915/gem/i915_gem_ttm.c static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev, · line 237

Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -1
-       i915_tt->cached_st = st;
+       i915_tt->cached_rsgt.table = *st;
+       kfree(st);

Will it work if the above just operates on the rsgt.table?

I'll change the shmem utility here to not allocate the struct sg_table and then we can operate on it directly.

Quoted 20 lines
Quoted 20 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +5 -1
+
         return 0;
 
   err_free_st:
-       shmem_free_st(st, filp->f_mapping, false, false);
+       shmem_free_st_table(st, filp->f_mapping, false, false);
+       kfree(st);
+
         return err;
   }
@@ -249,16 +249,29 @@ static void
 i915_ttm_tt_shmem_unpopulate(struct ttm_tt *ttm)
   {
         struct i915_ttm_tt *i915_tt = container_of(ttm,
 typeof(*i915_tt), ttm);
         bool backup = ttm->page_flags & TTM_TT_FLAG_SWAPPED;
+       struct sg_table *st = &i915_tt->cached_rsgt.table;
 
Quoted 8 lines
Quoted 6 lines

drivers/gpu/drm/i915/gem/i915_gem_ttm.c static void i915_ttm_tt_shmem_unpopulate(struct ttm_tt *ttm) · line 254

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -3
-       dma_unmap_sg(i915_tt->dev, i915_tt->cached_st->sgl,
-                    i915_tt->cached_st->nents,
-                    DMA_BIDIRECTIONAL);
+       if (st->sgl)

Can we ever hit this? I would have presumed not? Below also.

Yes, here's where we typically free the scatterlist.

What I meant to say: can the above ever not be true? i.e sgl == NULL

Quoted 725 lines
Quoted 425 lines
Quoted 414 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +17 -3
+               shmem_free_st_table(st,
+                                   file_inode(i915_tt->filp)-
 > i_mapping,
+                                   backup, backup);
+}
 
-       shmem_free_st(fetch_and_zero(&i915_tt->cached_st),
-                     file_inode(i915_tt->filp)->i_mapping,
-                     backup, backup);
+static void i915_ttm_tt_release(struct kref *ref)
+{
+       struct i915_ttm_tt *i915_tt =
+               container_of(ref, typeof(*i915_tt),
 cached_rsgt.kref);
+       struct sg_table *st = &i915_tt->cached_rsgt.table;
+
+       GEM_WARN_ON(st->sgl);
+
+       kfree(i915_tt);
   }
 
+static const struct i915_refct_sgt_ops tt_rsgt_ops = {
+       .release = i915_ttm_tt_release
+};
+
   static struct ttm_tt *i915_ttm_tt_create(struct ttm_buffer_object

*bo,
                                         uint32_t page_flags) {

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +3 -0
@@ -287,6 +300,9 @@ static struct ttm_tt *i915_ttm_tt_create(struct
 ttm_buffer_object *bo,
         if (ret)
                 goto err_free;
 
+       i915_refct_sgt_init_ops(&i915_tt->cached_rsgt, bo-
 > base.size,
+                               &tt_rsgt_ops);
+
         i915_tt->dev = obj->base.dev->dev;

        return &i915_tt->ttm;

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +4 -2
@@ -311,17 +327,15 @@ static int i915_ttm_tt_populate(struct
 ttm_device *bdev,
   static void i915_ttm_tt_unpopulate(struct ttm_device *bdev,
 struct ttm_tt *ttm)
   {
         struct i915_ttm_tt *i915_tt = container_of(ttm,
 typeof(*i915_tt), ttm);
+       struct sg_table *st = &i915_tt->cached_rsgt.table;
+
+       if (st->sgl)
+               dma_unmap_sgtable(i915_tt->dev, st,
 DMA_BIDIRECTIONAL, 0);
 
         if (i915_tt->is_shmem) {
                 i915_ttm_tt_shmem_unpopulate(ttm);
         } else {
-               if (i915_tt->cached_st) {
-                       dma_unmap_sgtable(i915_tt->dev, i915_tt-
Quoted 1 line

cached_st,

-                                         DMA_BIDIRECTIONAL, 0); -                       sg_free_table(i915_tt->cached_st); -                       kfree(i915_tt->cached_st);
-                       i915_tt->cached_st = NULL;
-               }
+               sg_free_table(st);
                ttm_pool_free(&bdev->pool, ttm);
        }
  }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -1
@@ -334,7 +348,7 @@ static void i915_ttm_tt_destroy(struct
 ttm_device *bdev, struct ttm_tt *ttm)
                 fput(i915_tt->filp);
 
         ttm_tt_fini(ttm);
-       kfree(i915_tt);
+       i915_refct_sgt_put(&i915_tt->cached_rsgt);
   }
 

  static bool i915_ttm_eviction_valuable(struct ttm_buffer_object
*bo,

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -2
@@ -376,12 +390,12 @@ static int i915_ttm_move_notify(struct
 ttm_buffer_object *bo)
         return 0;
   }
 
-static void i915_ttm_free_cached_io_st(struct drm_i915_gem_object
 *obj)
+static void i915_ttm_free_cached_io_rsgt(struct
 drm_i915_gem_object *obj)
   {
         struct radix_tree_iter iter;
         void __rcu **slot;
 
-       if (!obj->ttm.cached_io_st)
+       if (!obj->ttm.cached_io_rsgt)

                return;

        rcu_read_lock();

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -3
@@ -389,9 +403,8 @@ static void i915_ttm_free_cached_io_st(struct
 drm_i915_gem_object *obj)
                 radix_tree_delete(&obj->ttm.get_io_page.radix,
 iter.index);
         rcu_read_unlock();
 
-       sg_free_table(obj->ttm.cached_io_st);
-       kfree(obj->ttm.cached_io_st);
-       obj->ttm.cached_io_st = NULL;
+       i915_refct_sgt_put(obj->ttm.cached_io_rsgt);
+       obj->ttm.cached_io_rsgt = NULL;
   }

  static void

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -1
@@ -477,7 +490,7 @@ static int i915_ttm_purge(struct
 drm_i915_gem_object *obj)
         obj->write_domain = 0;
         obj->read_domains = 0;
         i915_ttm_adjust_gem_after_move(obj);
-       i915_ttm_free_cached_io_st(obj);
+       i915_ttm_free_cached_io_rsgt(obj);
         obj->mm.madv = __I915_MADV_PURGED;
         return 0;

  }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -1
@@ -532,7 +545,7 @@ static void i915_ttm_swap_notify(struct
 ttm_buffer_object *bo)
         int ret = i915_ttm_move_notify(bo);
 
         GEM_WARN_ON(ret);
-       GEM_WARN_ON(obj->ttm.cached_io_st);
+       GEM_WARN_ON(obj->ttm.cached_io_rsgt);
         if (!ret && obj->mm.madv != I915_MADV_WILLNEED)
                 i915_ttm_purge(obj);

  }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +7 -12
@@ -543,7 +556,7 @@ static void i915_ttm_delete_mem_notify(struct
 ttm_buffer_object *bo)
 
         if (likely(obj)) {
                 __i915_gem_object_pages_fini(obj);
-               i915_ttm_free_cached_io_st(obj);
+               i915_ttm_free_cached_io_rsgt(obj);
         }
   }
@@ -563,40 +576,35 @@ i915_ttm_region(struct ttm_device *bdev, int
 ttm_mem_type)
                                           ttm_mem_type -
 I915_PL_LMEM0);
   }
 
-static struct sg_table *i915_ttm_tt_get_st(struct ttm_tt *ttm)
+static struct i915_refct_sgt *i915_ttm_tt_get_st(struct ttm_tt
 *ttm)
   {
         struct i915_ttm_tt *i915_tt = container_of(ttm,
 typeof(*i915_tt), ttm);
         struct sg_table *st;
         int ret;
 
-       if (i915_tt->cached_st)
-               return i915_tt->cached_st;
-
-       st = kzalloc(sizeof(*st), GFP_KERNEL);
-       if (!st)
-               return ERR_PTR(-ENOMEM);
+       if (i915_tt->cached_rsgt.table.sgl)
+               return i915_refct_sgt_get(&i915_tt->cached_rsgt);
 
+       st = &i915_tt->cached_rsgt.table;
         ret = sg_alloc_table_from_pages_segment(st,
                         ttm->pages, ttm->num_pages,
                         0, (unsigned long)ttm->num_pages <<
 PAGE_SHIFT,
                         i915_sg_segment_size(), GFP_KERNEL);
         if (ret) {
-               kfree(st);
+               st->sgl = NULL;
                 return ERR_PTR(ret);
         }
 
         ret = dma_map_sgtable(i915_tt->dev, st, DMA_BIDIRECTIONAL,
 0);
         if (ret) {
                 sg_free_table(st);
-               kfree(st);
                 return ERR_PTR(ret);
         }
 
-       i915_tt->cached_st = st;
-       return st;
+       return i915_refct_sgt_get(&i915_tt->cached_rsgt);

  }

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +7 -2
-static struct sg_table *
+static struct i915_refct_sgt *
   i915_ttm_resource_get_st(struct drm_i915_gem_object *obj,
                          struct ttm_resource *res)
   {
@@ -610,7 +618,21 @@ i915_ttm_resource_get_st(struct
 drm_i915_gem_object *obj,
          * the resulting st. Might make sense for GGTT.
          */
         GEM_WARN_ON(!cpu_maps_iomem(res));
-       return intel_region_ttm_resource_to_st(obj->mm.region,
 res);
+       if (bo->resource == res) {
+               if (!obj->ttm.cached_io_rsgt) {
+                       struct i915_refct_sgt *rsgt;
+
+                       rsgt =
 intel_region_ttm_resource_to_rsgt(obj->mm.region,
+

res);
+                       if (IS_ERR(rsgt))
+                               return rsgt;

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +7 -0
+
+                       obj->ttm.cached_io_rsgt = rsgt;
+               }
+               return i915_refct_sgt_get(obj->ttm.cached_io_rsgt);
+       }
+
+       return intel_region_ttm_resource_to_rsgt(obj->mm.region,

res);
  }

  static int i915_ttm_accel_move(struct ttm_buffer_object *bo,

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -3
@@ -621,10 +643,7 @@ static int i915_ttm_accel_move(struct
 ttm_buffer_object *bo,
   {
         struct drm_i915_private *i915 = container_of(bo->bdev,
 typeof(*i915),
                                                      bdev);
-       struct ttm_resource_manager *src_man =
-               ttm_manager_type(bo->bdev, bo->resource->mem_type);
         struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
-       struct sg_table *src_st;
         struct i915_request *rq;

        struct ttm_tt *src_ttm = bo->ttm; enum i915_cache_level src_level, dst_level;

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -1
@@ -650,17 +669,22 @@ static int i915_ttm_accel_move(struct
 ttm_buffer_object *bo,
                 }
                 intel_engine_pm_put(i915->gt.migrate.context-
 > engine);
         } else {
-               src_st = src_man->use_tt ?

i915_ttm_tt_get_st(src_ttm) :
-                       obj->ttm.cached_io_st;
+               struct i915_refct_sgt *src_rsgt = +                       i915_ttm_resource_get_st(obj, bo-

Quoted 1 line

resource);

+
+               if (IS_ERR(src_rsgt))
+                       return PTR_ERR(src_rsgt);

                src_level = i915_ttm_cache_level(i915, bo-

Quoted 1 line

resource, src_ttm);

                intel_engine_pm_get(i915->gt.migrate.context-

Quoted 1 line

engine);

                ret = intel_context_migrate_copy(i915-

Quoted 1 line

gt.migrate.context,

-                                                NULL, src_st->sgl, src_level,
+                                                NULL, src_rsgt-

Quoted 1 line

table.sgl,

+                                                src_level,

gpu_binds_iomem(bo->resource),
                                                 dst_st->sgl,
dst_level,

gpu_binds_iomem(dst_mem),
                                                 &rq);
+               i915_refct_sgt_put(src_rsgt);
                if (!ret && rq) { i915_request_wait(rq, 0,
MAX_SCHEDULE_TIMEOUT);
                        i915_request_put(rq);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -2
@@ -674,13 +698,14 @@ static int i915_ttm_accel_move(struct
 ttm_buffer_object *bo,
   static void __i915_ttm_move(struct ttm_buffer_object *bo, bool
 clear,
                             struct ttm_resource *dst_mem,
                             struct ttm_tt *dst_ttm,
-                           struct sg_table *dst_st,
+                           struct i915_refct_sgt *dst_rsgt,
                             bool allow_accel)
   {
         int ret = -EINVAL;
 
         if (allow_accel)
-               ret = i915_ttm_accel_move(bo, clear, dst_mem,
 dst_ttm, dst_st);
+               ret = i915_ttm_accel_move(bo, clear, dst_mem,

dst_ttm,
+                                         &dst_rsgt->table);
        if (ret) {
                struct drm_i915_gem_object *obj =
i915_ttm_to_gem(bo);
                struct intel_memory_region *dst_reg, *src_reg;

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -697,12 +722,13 @@ static void __i915_ttm_move(struct
 ttm_buffer_object *bo, bool clear,
                 dst_iter = !cpu_maps_iomem(dst_mem) ?
                         ttm_kmap_iter_tt_init(&_dst_iter.tt,

dst_ttm) :
                        ttm_kmap_iter_iomap_init(&_dst_iter.io,
&dst_reg->iomap,
-                                                dst_st, dst_reg-

Quoted 1 line

region.start);

+                                                &dst_rsgt->table, +                                                dst_reg-

Quoted 1 line

region.start);

                src_iter = !cpu_maps_iomem(bo->resource) ? ttm_kmap_iter_tt_init(&_src_iter.tt, bo-

Quoted 1 line

ttm) :

                        ttm_kmap_iter_iomap_init(&_src_iter.io,
&src_reg->iomap,
-                                                obj-

Quoted 1 line

ttm.cached_io_st,

+                                                &obj-

Quoted 1 line

ttm.cached_io_rsgt->table,

                                                 src_reg-

Quoted 1 line

region.start);

                ttm_move_memcpy(clear, dst_mem->num_pages,
dst_iter, src_iter);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +10 -10
@@ -718,7 +744,7 @@ static int i915_ttm_move(struct
 ttm_buffer_object *bo, bool evict,
         struct ttm_resource_manager *dst_man =
                 ttm_manager_type(bo->bdev, dst_mem->mem_type);
         struct ttm_tt *ttm = bo->ttm;
-       struct sg_table *dst_st;
+       struct i915_refct_sgt *dst_rsgt;
         bool clear;
         int ret;
@@ -744,22 +770,24 @@ static int i915_ttm_move(struct
 ttm_buffer_object *bo, bool evict,
                         return ret;
         }
 
-       dst_st = i915_ttm_resource_get_st(obj, dst_mem);
-       if (IS_ERR(dst_st))
-               return PTR_ERR(dst_st);
+       dst_rsgt = i915_ttm_resource_get_st(obj, dst_mem);
+       if (IS_ERR(dst_rsgt))
+               return PTR_ERR(dst_rsgt);
 
         clear = !cpu_maps_iomem(bo->resource) && (!ttm ||
 !ttm_tt_is_populated(ttm));
         if (!(clear && ttm && !(ttm->page_flags &
 TTM_TT_FLAG_ZERO_ALLOC)))
-               __i915_ttm_move(bo, clear, dst_mem, bo->ttm,
 dst_st, true);
+               __i915_ttm_move(bo, clear, dst_mem, bo->ttm,
 dst_rsgt, true);
 
         ttm_bo_move_sync_cleanup(bo, dst_mem);
         i915_ttm_adjust_domains_after_move(obj);
-       i915_ttm_free_cached_io_st(obj);
+       i915_ttm_free_cached_io_rsgt(obj);
 
         if (gpu_binds_iomem(dst_mem) || cpu_maps_iomem(dst_mem)) {
-               obj->ttm.cached_io_st = dst_st;
-               obj->ttm.get_io_page.sg_pos = dst_st->sgl;
+               obj->ttm.cached_io_rsgt = dst_rsgt;
+               obj->ttm.get_io_page.sg_pos = dst_rsgt->table.sgl;
                 obj->ttm.get_io_page.sg_idx = 0;
+       } else {
+               i915_refct_sgt_put(dst_rsgt);
         }
 
         i915_ttm_adjust_lru(obj);
@@ -825,7 +853,6 @@ static int __i915_ttm_get_pages(struct
 drm_i915_gem_object *obj,
                 .interruptible = true,
                 .no_wait_gpu = false,
         };
-       struct sg_table *st;
         int real_num_busy;
         int ret;
@@ -862,12 +889,16 @@ static int __i915_ttm_get_pages(struct
 drm_i915_gem_object *obj,
         }
 
         if (!i915_gem_object_has_pages(obj)) {
-               /* Object either has a page vector or is an iomem

object */
-               st = bo->ttm ? i915_ttm_tt_get_st(bo->ttm) : obj-

Quoted 1 line

ttm.cached_io_st;

-               if (IS_ERR(st))
-                       return PTR_ERR(st);
+               struct i915_refct_sgt *rsgt =
+                       i915_ttm_resource_get_st(obj, bo-

Quoted 1 line

resource);

+
+               if (IS_ERR(rsgt))
+                       return PTR_ERR(rsgt);

-               __i915_gem_object_set_pages(obj, st, i915_sg_dma_sizes(st->sgl));
+               GEM_BUG_ON(obj->mm.rsgt);
+               obj->mm.rsgt = rsgt;
+               __i915_gem_object_set_pages(obj, &rsgt->table, +                                           i915_sg_dma_sizes(rsgt-

Quoted 1 line

table.sgl));

        }

        i915_ttm_adjust_lru(obj);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -941,6 +972,13 @@ static void i915_ttm_put_pages(struct
 drm_i915_gem_object *obj,
          * If the object is not destroyed next, The TTM eviction
Quoted 8 lines

logic
         * and shrinkers will move it out if needed. */
+
+       if (obj->mm.rsgt) {
+               i915_refct_sgt_put(obj->mm.rsgt); +               obj->mm.rsgt = NULL;
+       }

i915_refct_sgt_put(fetch_and_zero(&obj->mm.rsgt)) ?

Quoted 4 lines
Quoted 2 lines

+
+       i915_ttm_adjust_lru(obj);

Unrelated change, or do I need to look closer?

No that's unrelated. Probably a rebase mistake. Will remove.

Quoted 276 lines
Quoted 276 lines

  }

  static void i915_ttm_adjust_lru(struct drm_i915_gem_object *obj)

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -1
@@ -1278,7 +1316,7 @@ int i915_gem_obj_copy_ttm(struct
 drm_i915_gem_object *dst,
         struct ttm_operation_ctx ctx = {
                 .interruptible = intr,
         };
-       struct sg_table *dst_st;
+       struct i915_refct_sgt *dst_rsgt;
         int ret;
 

        assert_object_held(dst);

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +4 -4
@@ -1293,11 +1331,11 @@ int i915_gem_obj_copy_ttm(struct
 drm_i915_gem_object *dst,
         if (ret)
                 return ret;
 
-       dst_st = gpu_binds_iomem(dst_bo->resource) ?
-               dst->ttm.cached_io_st : i915_ttm_tt_get_st(dst_bo-
 > ttm);
-
+       dst_rsgt = i915_ttm_resource_get_st(dst, dst_bo->resource);
         __i915_ttm_move(src_bo, false, dst_bo->resource, dst_bo-
 > ttm,
-                       dst_st, allow_accel);
+                       dst_rsgt, allow_accel);
+
+       i915_refct_sgt_put(dst_rsgt);

        return 0;
  }

drivers/gpu/drm/i915/i915_scatterlist.c +15 -0
index 4a6712dca838..8a510ee5d1ad 100644
@@ -41,8 +41,32 @@ bool i915_sg_trim(struct sg_table *orig_st)
         return true;
   }
 
+static void i915_refct_sgt_release(struct kref *ref)
+{
+       struct i915_refct_sgt *rsgt =
+               container_of(ref, typeof(*rsgt), kref);
+
+       sg_free_table(&rsgt->table);
+       kfree(rsgt);
+}
+
+static const struct i915_refct_sgt_ops rsgt_ops = {
+       .release = i915_refct_sgt_release
+};
+
+/**
+ * i915_refct_sgt_init - Initialize a struct i915_refct_sgt with

default ops
+ * @rsgt: The struct i915_refct_sgt to initialize.
+ * size: The size of the underlying memory buffer.
+ */

drivers/gpu/drm/i915/i915_scatterlist.c +5 -1
+void i915_refct_sgt_init(struct i915_refct_sgt *rsgt, size_t size)
+{
+       i915_refct_sgt_init_ops(rsgt, size, &rsgt_ops);
+}
+
   /**
- * i915_sg_from_mm_node - Create an sg_table from a struct

drm_mm_node
+ * i915_rsgt_from_mm_node - Create a refcounted sg_table from a struct
+ * drm_mm_node
   * @node: The drm_mm_node.
   * @region_start: An offset to add to the dma addresses of the sg
list.
   *

drivers/gpu/drm/i915/i915_scatterlist.c +0 -0
@@ -50,25 +74,28 @@ bool i915_sg_trim(struct sg_table *orig_st)
    * taking a maximum segment length into account, splitting into

segments
   * if necessary.
   *
- * Return: A pointer to a kmalloced struct sg_table on success, negative
+ * Return: A pointer to a kmalloced struct i915_refct_sgt on success, negative
   * error code cast to an error pointer on failure. */
-struct sg_table *i915_sg_from_mm_node(const struct drm_mm_node *node,
-                                     u64 region_start) +struct i915_refct_sgt *i915_rsgt_from_mm_node(const struct drm_mm_node *node,
+                                             u64 region_start)
  {
        const u64 max_segment = SZ_1G; /* Do we have a limit on
this? */
        u64 segment_pages = max_segment >> PAGE_SHIFT; u64 block_size, offset, prev_end;
+       struct i915_refct_sgt *rsgt;
        struct sg_table *st;
        struct scatterlist *sg;

-       st = kmalloc(sizeof(*st), GFP_KERNEL); -       if (!st)
+       rsgt = kmalloc(sizeof(*rsgt), GFP_KERNEL); +       if (!rsgt)
                return ERR_PTR(-ENOMEM);

+       i915_refct_sgt_init(rsgt, node->size << PAGE_SHIFT); +       st = &rsgt->table;
        if (sg_alloc_table(st, DIV_ROUND_UP(node->size,
segment_pages),
                           GFP_KERNEL)) {
-               kfree(st);
+               i915_refct_sgt_put(rsgt);
                return ERR_PTR(-ENOMEM);
        }

drivers/gpu/drm/i915/i915_scatterlist.c +2 -2
@@ -104,11 +131,11 @@ struct sg_table *i915_sg_from_mm_node(const
 struct drm_mm_node *node,
         sg_mark_end(sg);
         i915_sg_trim(st);
 
-       return st;
+       return rsgt;
   }
 
   /**
- * i915_sg_from_buddy_resource - Create an sg_table from a struct
+ * i915_rsgt_from_buddy_resource - Create a refcounted sg_table

from a struct
   * i915_buddy_block list
   * @res: The struct i915_ttm_buddy_resource.
   * @region_start: An offset to add to the dma addresses of the sg
list.

drivers/gpu/drm/i915/i915_scatterlist.c +0 -0
@@ -117,11 +144,11 @@ struct sg_table *i915_sg_from_mm_node(const
 struct drm_mm_node *node,
    * taking a maximum segment length into account, splitting into

segments
   * if necessary.
   *
- * Return: A pointer to a kmalloced struct sg_table on success, negative
+ * Return: A pointer to a kmalloced struct i915_refct_sgts on success, negative
   * error code cast to an error pointer on failure. */
-struct sg_table *i915_sg_from_buddy_resource(struct ttm_resource *res,
-                                            u64 region_start) +struct i915_refct_sgt *i915_rsgt_from_buddy_resource(struct ttm_resource *res,
+                                                    u64 region_start)
  {
        struct i915_ttm_buddy_resource *bman_res =
to_ttm_buddy_resource(res);
        const u64 size = res->num_pages << PAGE_SHIFT;

drivers/gpu/drm/i915/i915_scatterlist.c +7 -4
@@ -129,18 +156,21 @@ struct sg_table
 *i915_sg_from_buddy_resource(struct ttm_resource *res,
         struct i915_buddy_mm *mm = bman_res->mm;
         struct list_head *blocks = &bman_res->blocks;
         struct i915_buddy_block *block;
+       struct i915_refct_sgt *rsgt;
         struct scatterlist *sg;
         struct sg_table *st;
         resource_size_t prev_end;
 
         GEM_BUG_ON(list_empty(blocks));
 
-       st = kmalloc(sizeof(*st), GFP_KERNEL);
-       if (!st)
+       rsgt = kmalloc(sizeof(*rsgt), GFP_KERNEL);
+       if (!rsgt)
                 return ERR_PTR(-ENOMEM);
 
+       i915_refct_sgt_init(rsgt, size);
+       st = &rsgt->table;
         if (sg_alloc_table(st, res->num_pages, GFP_KERNEL)) {
-               kfree(st);
+               i915_refct_sgt_put(rsgt);
                 return ERR_PTR(-ENOMEM);
         }
@@ -181,7 +211,7 @@ struct sg_table
 *i915_sg_from_buddy_resource(struct ttm_resource *res,
         sg_mark_end(sg);
         i915_sg_trim(st);
 
-       return st;
+       return rsgt;
   }
 

  #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)

drivers/gpu/drm/i915/i915_scatterlist.h +2 -2
index b8bd5925b03f..321fd4a9f777 100644
@@ -144,10 +144,78 @@ static inline unsigned int
 i915_sg_segment_size(void)
 
   bool i915_sg_trim(struct sg_table *orig_st);
 
-struct sg_table *i915_sg_from_mm_node(const struct drm_mm_node
 *node,
-                                     u64 region_start);
+/**
+ * struct i915_refct_sgt_ops - Operations structure for struct

i915_refct_sgt
+ */
+struct i915_refct_sgt_ops {
+       /**
+        * release() - Free the memory of the struct i915_refct_sgt +        * @ref: struct kref that is embedded in the struct i915_refct_sgt
+        */
+       void (*release)(struct kref *ref);

drivers/gpu/drm/i915/i915_scatterlist.h +6 -0
+};
+
+/**
+ * struct i915_refct_sgt - A refcounted scatter-gather table
+ * @kref: struct kref for refcounting
+ * @table: struct sg_table holding the scatter-gather table

itself. Note that
+ * @table->sgl = NULL can be used to determine whether a scatter- gather table
+ * is present or not.
+ * @size: The size in bytes of the underlying memory buffer
+ * @ops: The operations structure.
+ */

drivers/gpu/drm/i915/i915_scatterlist.h +30 -0
+struct i915_refct_sgt {
+       struct kref kref;
+       struct sg_table table;
+       size_t size;
+       const struct i915_refct_sgt_ops *ops;
+};
+
+/**
+ * i915_refct_sgt_put - Put a refcounted sg-table
+ * @rsgt the struct i915_refct_sgt to put.
+ */
+static inline void i915_refct_sgt_put(struct i915_refct_sgt *rsgt)
+{
+       if (rsgt)
+               kref_put(&rsgt->kref, rsgt->ops->release);
+}
+
+/**
+ * i915_refct_sgt_get - Get a refcounted sg-table
+ * @rsgt the struct i915_refct_sgt to get.
+ */
+static inline struct i915_refct_sgt *
+i915_refct_sgt_get(struct i915_refct_sgt *rsgt)
+{
+       kref_get(&rsgt->kref);
+       return rsgt;
+}
+
+/**
+ * i915_refct_sgt_init_ops - Initialize a refcounted sg-list with

a custom
+ * operations structure
+ * @rsgt The struct i915_refct_sgt to initialize.
+ * @size: Size in bytes of the underlying memory buffer.
+ * @ops: A customized operations structure in case the refcounted sg-list
+ * is embedded into another structure.
+ */
+static inline void i915_refct_sgt_init_ops(struct i915_refct_sgt *rsgt,
+                                          size_t size, +                                          const struct i915_refct_sgt_ops *ops)
+{
+       kref_init(&rsgt->kref);

Quoted 10 lines
Quoted 4 lines

+       rsgt->table.sgl = NULL;
+       rsgt->size = size;
+       rsgt->ops = ops;
+}

Could maybe make this __i915_refct_sgt_init(), since it inits more than
just the ops?

Will change.

Thanks,
Thomas

#5 lore raw

Re: [PATCH v2 1/3] drm/i915: Introduce refcounted sg-tables

Quoted 238 lines · Matthew Auld
Quoted 237 lines · Thomas Hellström
Quoted 67 lines · Matthew Auld
Quoted 55 lines · Thomas Hellström

As we start to introduce asynchronous failsafe object migration, where we update the object state and then submit asynchronous commands we need to record what memory resources are actually used by various part of the command stream. Initially for three purposes:

1) Error capture.
2) Asynchronous migration error recovery.
3) Asynchronous vma bind.

At the time where these happens, the object state may have been updated
to be several migrations ahead and object sg-tables discarded.

In order to make it possible to keep sg-tables with memory resource information for these operations, introduce refcounted sg-tables that
aren't freed until the last user is done with them.

The alternative would be to reference information sitting on the corresponding ttm_resources which typically have the same lifetime as
these refcountes sg_tables, but that leads to other awkward constructs:
Due to the design direction chosen for ttm resource managers that would
lead to diamond-style inheritance, the LMEM resources may sometimes be
prematurely freed, and finally the subclassed struct ttm_resource would
have to bleed into the asynchronous vma bind code.

---
   drivers/gpu/drm/i915/gem/i915_gem_object.h    |   4 +- .../gpu/drm/i915/gem/i915_gem_object_types.h  |   3 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  16 +- drivers/gpu/drm/i915/gem/i915_gem_ttm.c       | 188 +++++++++++--
-----

   drivers/gpu/drm/i915/i915_scatterlist.c       |  62 ++++--
   drivers/gpu/drm/i915/i915_scatterlist.h       |  76 ++++++-
   drivers/gpu/drm/i915/intel_region_ttm.c       |  15 +-
   drivers/gpu/drm/i915/intel_region_ttm.h       |   5 +-
   drivers/gpu/drm/i915/selftests/mock_region.c  |  12 +-
   9 files changed, 262 insertions(+), 119 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.h +0 -0
index a5479ac7a4ad..c5ab364d4311 100644
@@ -624,8 +624,8 @@ struct sg_table *shmem_alloc_st(struct
 drm_i915_private *i915,

                                 size_t size, struct intel_memory_region *mr,

Quoted 8 lines

                                 struct address_space *mapping, unsigned int max_segment); -void shmem_free_st(struct sg_table *st, struct address_space *mapping,
-                  bool dirty, bool backup);
+void shmem_free_st_table(struct sg_table *st, struct address_space *mapping,
+                        bool dirty, bool backup);

s/st_table/sg_table/?

Quoted 1 line

I thought st was shorthand for sg_table? Maybe shmem_sg_free_table?

Yes the naming is indeed a bit unfortunate here. To be consistent with the core's sg_free_table(), I changed to shmem_sg_free_table() / shmem_sg_alloc_table.

Quoted 127 lines
Quoted 127 lines

   void __shmem_writeback(size_t size, struct address_space *mapping);
      #ifdef CONFIG_MMU_NOTIFIER

drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
index a4b69a43b898..604ed5ad77f5 100644
@@ -544,6 +544,7 @@ struct drm_i915_gem_object {
                   */
                  struct list_head region_link;
    +               struct i915_refct_sgt *rsgt;
                  struct sg_table *pages;
                  void *mapping;
    @@ -597,7 +598,7 @@ struct drm_i915_gem_object {

         } mm;
            struct {
-               struct sg_table *cached_io_st;
+               struct i915_refct_sgt *cached_io_rsgt; struct i915_gem_object_page_iter get_io_page; struct drm_i915_gem_object *backup; bool created:1;

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
index 01f332d8dbde..67c6bee695c7 100644
@@ -25,8 +25,8 @@ static void check_release_pagevec(struct pagevec
 *pvec)
          cond_resched();
    }

   -void shmem_free_st(struct sg_table *st, struct address_space *mapping,
-                  bool dirty, bool backup)
+void shmem_free_st_table(struct sg_table *st, struct address_space *mapping,
+                        bool dirty, bool backup)
   {
         struct sgt_iter sgt_iter;
         struct pagevec pvec;

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -1
@@ -49,7 +49,6 @@ void shmem_free_st(struct sg_table *st, struct
 address_space *mapping,
                  check_release_pagevec(&pvec);
             sg_free_table(st);
-       kfree(st);
    }
       struct sg_table *shmem_alloc_st(struct drm_i915_private *i915,
@@ -171,7 +170,8 @@ struct sg_table *shmem_alloc_st(struct
 drm_i915_private *i915,

   err_sg:
         sg_mark_end(sg);
         if (sg != st->sgl) {
-               shmem_free_st(st, mapping, false, false); +               shmem_free_st_table(st, mapping, false, false); +               kfree(st);
         } else {
                 mapping_clear_unevictable(mapping); sg_free_table(st);

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
@@ -254,7 +254,8 @@ static int shmem_get_pages(struct
 drm_i915_gem_object *obj)
          return 0;

      err_pages:
-       shmem_free_st(st, mapping, false, false);
+       shmem_free_st_table(st, mapping, false, false); +       kfree(st);
         /*
          * shmemfs first checks if there is enough memory to allocate the page
          * and reports ENOSPC should there be insufficient, along with the usual

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
@@ -374,8 +375,9 @@ void i915_gem_object_put_pages_shmem(struct

drm_i915_gem_object *obj, struct sg_
         if (i915_gem_object_needs_bit17_swizzle(obj)) i915_gem_object_save_bit_17_swizzle(obj, pages); -       shmem_free_st(pages, file_inode(obj->base.filp)->i_mapping, -                     obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+       shmem_free_st_table(pages, file_inode(obj->base.filp)-

Quoted 1 line

i_mapping,

+                           obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+       kfree(pages);
         obj->mm.dirty = false;
   }
   diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
index 4fd2edb20dd9..6826e3859e18 100644

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -34,7 +34,7 @@
     * struct i915_ttm_tt - TTM page vector with additional private

information
    * @ttm: The base TTM page vector.
    * @dev: The struct device used for dma mapping and unmapping.
- * @cached_st: The cached scatter-gather table.
+ * @cached_rsgt: The cached scatter-gather table.
    * @is_shmem: Set if using shmem.
    * @filp: The shmem file, if using shmem backend.
    *

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +4 -7
@@ -47,7 +47,7 @@
    struct i915_ttm_tt {
          struct ttm_tt ttm;
          struct device *dev;
-       struct sg_table *cached_st;
+       struct i915_refct_sgt cached_rsgt;
             bool is_shmem;
          struct file *filp;
@@ -221,14 +221,10 @@ static int i915_ttm_tt_shmem_populate(struct
 ttm_device *bdev,
          if (IS_ERR(st))
                  return PTR_ERR(st);
    -       err = dma_map_sg_attrs(i915_tt->dev,
-                              st->sgl, st->nents,
-                              DMA_BIDIRECTIONAL,
-                              DMA_ATTR_SKIP_CPU_SYNC);
-       if (err <= 0) {
-               err = -EINVAL;
+       err = dma_map_sgtable(i915_tt->dev, st, DMA_BIDIRECTIONAL,
+                             DMA_ATTR_SKIP_CPU_SYNC);
+       if (err)
                  goto err_free_st;
-       }
             i = 0;
          for_each_sgt_page(page, sgt_iter, st)
@@ -237,11 +233,15 @@ static int i915_ttm_tt_shmem_populate(struct
Quoted 8 lines

drivers/gpu/drm/i915/gem/i915_gem_ttm.c static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev, · line 237

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -0
 ttm_device *bdev,
          if (ttm->page_flags & TTM_TT_FLAG_SWAPPED)
                  ttm->page_flags &= ~TTM_TT_FLAG_SWAPPED;
    -       i915_tt->cached_st = st;
+       i915_tt->cached_rsgt.table = *st;
+       kfree(st);

Will it work if the above just operates on the rsgt.table?

I'll change the shmem utility here to not allocate the struct sg_table and then we can operate on it directly.

Quoted 23 lines
Quoted 13 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -0
+
          return 0;

      err_free_st:
-       shmem_free_st(st, filp->f_mapping, false, false); +       shmem_free_st_table(st, filp->f_mapping, false, false); +       kfree(st);
+
         return err;
   }
   @@ -249,16 +249,29 @@ static void i915_ttm_tt_shmem_unpopulate(struct ttm_tt *ttm)
   {

Quoted 8 lines

         struct i915_ttm_tt *i915_tt = container_of(ttm, typeof(*i915_tt), ttm);
         bool backup = ttm->page_flags & TTM_TT_FLAG_SWAPPED; +       struct sg_table *st = &i915_tt->cached_rsgt.table; -       dma_unmap_sg(i915_tt->dev, i915_tt->cached_st->sgl, -                    i915_tt->cached_st->nents,
-                    DMA_BIDIRECTIONAL);
+       if (st->sgl)

Can we ever hit this? I would have presumed not? Below also.

Quoted 3 lines
Quoted 1 line

Yes, here's where we typically free the scatterlist.

What I meant to say: can the above ever not be true? i.e sgl == NULL

Hm, Yes I think it can. If we're populating a non-shmem ttm tt, that sg-list is, IIRC allocated lazily on first use. Although I haven't analyzed in detail whether it can actually be populated and then not lazily allocated under the same lock.

#6 lore raw

Re: [PATCH v2 1/3] drm/i915: Introduce refcounted sg-tables

Quoted 240 lines · Thomas Hellström
Quoted 238 lines · Matthew Auld
Quoted 237 lines · Thomas Hellström
Quoted 67 lines · Matthew Auld
Quoted 55 lines · Thomas Hellström

As we start to introduce asynchronous failsafe object migration, where we update the object state and then submit asynchronous commands we need to record what memory resources are actually used by various part of the command stream. Initially for three purposes:

1) Error capture.
2) Asynchronous migration error recovery.
3) Asynchronous vma bind.

At the time where these happens, the object state may have been updated
to be several migrations ahead and object sg-tables discarded.

In order to make it possible to keep sg-tables with memory resource information for these operations, introduce refcounted sg-tables that
aren't freed until the last user is done with them.

The alternative would be to reference information sitting on the corresponding ttm_resources which typically have the same lifetime as
these refcountes sg_tables, but that leads to other awkward constructs:
Due to the design direction chosen for ttm resource managers that would
lead to diamond-style inheritance, the LMEM resources may sometimes be
prematurely freed, and finally the subclassed struct ttm_resource would
have to bleed into the asynchronous vma bind code.

---
   drivers/gpu/drm/i915/gem/i915_gem_object.h    |   4 +- .../gpu/drm/i915/gem/i915_gem_object_types.h  |   3 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  16 +- drivers/gpu/drm/i915/gem/i915_gem_ttm.c       | 188 +++++++++++--
-----

   drivers/gpu/drm/i915/i915_scatterlist.c       |  62 ++++--
   drivers/gpu/drm/i915/i915_scatterlist.h       |  76 ++++++-
   drivers/gpu/drm/i915/intel_region_ttm.c       |  15 +-
   drivers/gpu/drm/i915/intel_region_ttm.h       |   5 +-
   drivers/gpu/drm/i915/selftests/mock_region.c  |  12 +-
   9 files changed, 262 insertions(+), 119 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.h +0 -0
index a5479ac7a4ad..c5ab364d4311 100644
@@ -624,8 +624,8 @@ struct sg_table *shmem_alloc_st(struct
 drm_i915_private *i915,

                                 size_t size, struct intel_memory_region *mr,

Quoted 8 lines

                                 struct address_space *mapping, unsigned int max_segment); -void shmem_free_st(struct sg_table *st, struct address_space *mapping,
-                  bool dirty, bool backup);
+void shmem_free_st_table(struct sg_table *st, struct address_space *mapping,
+                        bool dirty, bool backup);

s/st_table/sg_table/?

Quoted 1 line

I thought st was shorthand for sg_table? Maybe shmem_sg_free_table?

Yes the naming is indeed a bit unfortunate here. To be consistent with the core's sg_free_table(), I changed to shmem_sg_free_table() / shmem_sg_alloc_table.

Quoted 127 lines
Quoted 127 lines

   void __shmem_writeback(size_t size, struct address_space *mapping);
      #ifdef CONFIG_MMU_NOTIFIER

drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
index a4b69a43b898..604ed5ad77f5 100644
@@ -544,6 +544,7 @@ struct drm_i915_gem_object {
                   */
                  struct list_head region_link;
    +               struct i915_refct_sgt *rsgt;
                  struct sg_table *pages;
                  void *mapping;
    @@ -597,7 +598,7 @@ struct drm_i915_gem_object {

         } mm;
            struct {
-               struct sg_table *cached_io_st;
+               struct i915_refct_sgt *cached_io_rsgt; struct i915_gem_object_page_iter get_io_page; struct drm_i915_gem_object *backup; bool created:1;

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
index 01f332d8dbde..67c6bee695c7 100644
@@ -25,8 +25,8 @@ static void check_release_pagevec(struct pagevec
 *pvec)
          cond_resched();
    }

   -void shmem_free_st(struct sg_table *st, struct address_space *mapping,
-                  bool dirty, bool backup)
+void shmem_free_st_table(struct sg_table *st, struct address_space *mapping,
+                        bool dirty, bool backup)
   {
         struct sgt_iter sgt_iter;
         struct pagevec pvec;

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -1
@@ -49,7 +49,6 @@ void shmem_free_st(struct sg_table *st, struct
 address_space *mapping,
                  check_release_pagevec(&pvec);
             sg_free_table(st);
-       kfree(st);
    }
       struct sg_table *shmem_alloc_st(struct drm_i915_private *i915,
@@ -171,7 +170,8 @@ struct sg_table *shmem_alloc_st(struct
 drm_i915_private *i915,

   err_sg:
         sg_mark_end(sg);
         if (sg != st->sgl) {
-               shmem_free_st(st, mapping, false, false); +               shmem_free_st_table(st, mapping, false, false); +               kfree(st);
         } else {
                 mapping_clear_unevictable(mapping); sg_free_table(st);

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
@@ -254,7 +254,8 @@ static int shmem_get_pages(struct
 drm_i915_gem_object *obj)
          return 0;

      err_pages:
-       shmem_free_st(st, mapping, false, false);
+       shmem_free_st_table(st, mapping, false, false); +       kfree(st);
         /*
          * shmemfs first checks if there is enough memory to allocate the page
          * and reports ENOSPC should there be insufficient, along with the usual

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
@@ -374,8 +375,9 @@ void i915_gem_object_put_pages_shmem(struct

drm_i915_gem_object *obj, struct sg_
         if (i915_gem_object_needs_bit17_swizzle(obj)) i915_gem_object_save_bit_17_swizzle(obj, pages); -       shmem_free_st(pages, file_inode(obj->base.filp)->i_mapping, -                     obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+       shmem_free_st_table(pages, file_inode(obj->base.filp)-

Quoted 1 line

i_mapping,

+                           obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+       kfree(pages);
         obj->mm.dirty = false;
   }
   diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
index 4fd2edb20dd9..6826e3859e18 100644

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -34,7 +34,7 @@
     * struct i915_ttm_tt - TTM page vector with additional private

information
    * @ttm: The base TTM page vector.
    * @dev: The struct device used for dma mapping and unmapping.
- * @cached_st: The cached scatter-gather table.
+ * @cached_rsgt: The cached scatter-gather table.
    * @is_shmem: Set if using shmem.
    * @filp: The shmem file, if using shmem backend.
    *

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +4 -7
@@ -47,7 +47,7 @@
    struct i915_ttm_tt {
          struct ttm_tt ttm;
          struct device *dev;
-       struct sg_table *cached_st;
+       struct i915_refct_sgt cached_rsgt;
             bool is_shmem;
          struct file *filp;
@@ -221,14 +221,10 @@ static int i915_ttm_tt_shmem_populate(struct
 ttm_device *bdev,
          if (IS_ERR(st))
                  return PTR_ERR(st);
    -       err = dma_map_sg_attrs(i915_tt->dev,
-                              st->sgl, st->nents,
-                              DMA_BIDIRECTIONAL,
-                              DMA_ATTR_SKIP_CPU_SYNC);
-       if (err <= 0) {
-               err = -EINVAL;
+       err = dma_map_sgtable(i915_tt->dev, st, DMA_BIDIRECTIONAL,
+                             DMA_ATTR_SKIP_CPU_SYNC);
+       if (err)
                  goto err_free_st;
-       }
             i = 0;
          for_each_sgt_page(page, sgt_iter, st)
@@ -237,11 +233,15 @@ static int i915_ttm_tt_shmem_populate(struct
Quoted 8 lines

drivers/gpu/drm/i915/gem/i915_gem_ttm.c static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev, · line 237

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -0
 ttm_device *bdev,
          if (ttm->page_flags & TTM_TT_FLAG_SWAPPED)
                  ttm->page_flags &= ~TTM_TT_FLAG_SWAPPED;
    -       i915_tt->cached_st = st;
+       i915_tt->cached_rsgt.table = *st;
+       kfree(st);

Will it work if the above just operates on the rsgt.table?

I'll change the shmem utility here to not allocate the struct sg_table and then we can operate on it directly.

Quoted 23 lines
Quoted 13 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -0
+
          return 0;

      err_free_st:
-       shmem_free_st(st, filp->f_mapping, false, false); +       shmem_free_st_table(st, filp->f_mapping, false, false); +       kfree(st);
+
         return err;
   }
   @@ -249,16 +249,29 @@ static void i915_ttm_tt_shmem_unpopulate(struct ttm_tt *ttm)
   {

Quoted 8 lines

         struct i915_ttm_tt *i915_tt = container_of(ttm, typeof(*i915_tt), ttm);
         bool backup = ttm->page_flags & TTM_TT_FLAG_SWAPPED; +       struct sg_table *st = &i915_tt->cached_rsgt.table; -       dma_unmap_sg(i915_tt->dev, i915_tt->cached_st->sgl, -                    i915_tt->cached_st->nents,
-                    DMA_BIDIRECTIONAL);
+       if (st->sgl)

Can we ever hit this? I would have presumed not? Below also.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Yes, here's where we typically free the scatterlist.

What I meant to say: can the above ever not be true? i.e sgl == NULL

Hm, Yes I think it can. If we're populating a non-shmem ttm tt, that sg-list is, IIRC allocated lazily on first use. Although I haven't analyzed in detail whether it can actually be populated and then not lazily allocated under the same lock.

Oh right. I guess we could maybe drop the check in the shmem part?

Quoted 2 lines
#7 lore raw

Re: [PATCH v2 1/3] drm/i915: Introduce refcounted sg-tables

Quoted 241 lines · Matthew Auld
Quoted 240 lines · Thomas Hellström
Quoted 238 lines · Matthew Auld
Quoted 237 lines · Thomas Hellström
Quoted 67 lines · Matthew Auld
Quoted 55 lines · Thomas Hellström

As we start to introduce asynchronous failsafe object migration, where we update the object state and then submit asynchronous commands we need to record what memory resources are actually used by various part of the command stream. Initially for three purposes:

1) Error capture.
2) Asynchronous migration error recovery.
3) Asynchronous vma bind.

At the time where these happens, the object state may have been updated
to be several migrations ahead and object sg-tables discarded.

In order to make it possible to keep sg-tables with memory resource information for these operations, introduce refcounted sg-tables that
aren't freed until the last user is done with them.

The alternative would be to reference information sitting on the corresponding ttm_resources which typically have the same lifetime as
these refcountes sg_tables, but that leads to other awkward constructs:
Due to the design direction chosen for ttm resource managers that would
lead to diamond-style inheritance, the LMEM resources may sometimes be
prematurely freed, and finally the subclassed struct ttm_resource would
have to bleed into the asynchronous vma bind code.

---
   drivers/gpu/drm/i915/gem/i915_gem_object.h    |   4 +- .../gpu/drm/i915/gem/i915_gem_object_types.h  |   3 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  16 +- drivers/gpu/drm/i915/gem/i915_gem_ttm.c       | 188 +++++++++++--
-----

   drivers/gpu/drm/i915/i915_scatterlist.c       |  62 ++++--
   drivers/gpu/drm/i915/i915_scatterlist.h       |  76 ++++++-
   drivers/gpu/drm/i915/intel_region_ttm.c       |  15 +-
   drivers/gpu/drm/i915/intel_region_ttm.h       |   5 +-
   drivers/gpu/drm/i915/selftests/mock_region.c  |  12 +-
   9 files changed, 262 insertions(+), 119 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.h +0 -0
index a5479ac7a4ad..c5ab364d4311 100644
@@ -624,8 +624,8 @@ struct sg_table *shmem_alloc_st(struct
 drm_i915_private *i915,

                                 size_t size, struct intel_memory_region *mr,

Quoted 8 lines

                                 struct address_space *mapping, unsigned int max_segment); -void shmem_free_st(struct sg_table *st, struct address_space *mapping,
-                  bool dirty, bool backup);
+void shmem_free_st_table(struct sg_table *st, struct address_space *mapping,
+                        bool dirty, bool backup);

s/st_table/sg_table/?

Quoted 1 line

I thought st was shorthand for sg_table? Maybe shmem_sg_free_table?

Yes the naming is indeed a bit unfortunate here. To be consistent with the core's sg_free_table(), I changed to shmem_sg_free_table() / shmem_sg_alloc_table.

Quoted 127 lines
Quoted 127 lines

   void __shmem_writeback(size_t size, struct address_space *mapping);
      #ifdef CONFIG_MMU_NOTIFIER

drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
index a4b69a43b898..604ed5ad77f5 100644
@@ -544,6 +544,7 @@ struct drm_i915_gem_object {
                   */
                  struct list_head region_link;
    +               struct i915_refct_sgt *rsgt;
                  struct sg_table *pages;
                  void *mapping;
    @@ -597,7 +598,7 @@ struct drm_i915_gem_object {

         } mm;
            struct {
-               struct sg_table *cached_io_st;
+               struct i915_refct_sgt *cached_io_rsgt; struct i915_gem_object_page_iter get_io_page; struct drm_i915_gem_object *backup; bool created:1;

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
index 01f332d8dbde..67c6bee695c7 100644
@@ -25,8 +25,8 @@ static void check_release_pagevec(struct pagevec
 *pvec)
          cond_resched();
    }

   -void shmem_free_st(struct sg_table *st, struct address_space *mapping,
-                  bool dirty, bool backup)
+void shmem_free_st_table(struct sg_table *st, struct address_space *mapping,
+                        bool dirty, bool backup)
   {
         struct sgt_iter sgt_iter;
         struct pagevec pvec;

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -1
@@ -49,7 +49,6 @@ void shmem_free_st(struct sg_table *st, struct
 address_space *mapping,
                  check_release_pagevec(&pvec);
             sg_free_table(st);
-       kfree(st);
    }
       struct sg_table *shmem_alloc_st(struct drm_i915_private *i915,
@@ -171,7 +170,8 @@ struct sg_table *shmem_alloc_st(struct
 drm_i915_private *i915,

   err_sg:
         sg_mark_end(sg);
         if (sg != st->sgl) {
-               shmem_free_st(st, mapping, false, false); +               shmem_free_st_table(st, mapping, false, false); +               kfree(st);
         } else {
                 mapping_clear_unevictable(mapping); sg_free_table(st);

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
@@ -254,7 +254,8 @@ static int shmem_get_pages(struct
 drm_i915_gem_object *obj)
          return 0;

      err_pages:
-       shmem_free_st(st, mapping, false, false);
+       shmem_free_st_table(st, mapping, false, false); +       kfree(st);
         /*
          * shmemfs first checks if there is enough memory to allocate the page
          * and reports ENOSPC should there be insufficient, along with the usual

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
@@ -374,8 +375,9 @@ void i915_gem_object_put_pages_shmem(struct

drm_i915_gem_object *obj, struct sg_
         if (i915_gem_object_needs_bit17_swizzle(obj)) i915_gem_object_save_bit_17_swizzle(obj, pages); -       shmem_free_st(pages, file_inode(obj->base.filp)->i_mapping, -                     obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+       shmem_free_st_table(pages, file_inode(obj->base.filp)-

Quoted 1 line

i_mapping,

+                           obj->mm.dirty, obj->mm.madv == I915_MADV_WILLNEED);
+       kfree(pages);
         obj->mm.dirty = false;
   }
   diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
index 4fd2edb20dd9..6826e3859e18 100644

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -34,7 +34,7 @@
     * struct i915_ttm_tt - TTM page vector with additional private

information
    * @ttm: The base TTM page vector.
    * @dev: The struct device used for dma mapping and unmapping.
- * @cached_st: The cached scatter-gather table.
+ * @cached_rsgt: The cached scatter-gather table.
    * @is_shmem: Set if using shmem.
    * @filp: The shmem file, if using shmem backend.
    *

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +4 -7
@@ -47,7 +47,7 @@
    struct i915_ttm_tt {
          struct ttm_tt ttm;
          struct device *dev;
-       struct sg_table *cached_st;
+       struct i915_refct_sgt cached_rsgt;
             bool is_shmem;
          struct file *filp;
@@ -221,14 +221,10 @@ static int i915_ttm_tt_shmem_populate(struct
 ttm_device *bdev,
          if (IS_ERR(st))
                  return PTR_ERR(st);
    -       err = dma_map_sg_attrs(i915_tt->dev,
-                              st->sgl, st->nents,
-                              DMA_BIDIRECTIONAL,
-                              DMA_ATTR_SKIP_CPU_SYNC);
-       if (err <= 0) {
-               err = -EINVAL;
+       err = dma_map_sgtable(i915_tt->dev, st, DMA_BIDIRECTIONAL,
+                             DMA_ATTR_SKIP_CPU_SYNC);
+       if (err)
                  goto err_free_st;
-       }
             i = 0;
          for_each_sgt_page(page, sgt_iter, st)
@@ -237,11 +233,15 @@ static int i915_ttm_tt_shmem_populate(struct
Quoted 8 lines

drivers/gpu/drm/i915/gem/i915_gem_ttm.c static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev, · line 237

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -0
 ttm_device *bdev,
          if (ttm->page_flags & TTM_TT_FLAG_SWAPPED)
                  ttm->page_flags &= ~TTM_TT_FLAG_SWAPPED;
    -       i915_tt->cached_st = st;
+       i915_tt->cached_rsgt.table = *st;
+       kfree(st);

Will it work if the above just operates on the rsgt.table?

I'll change the shmem utility here to not allocate the struct sg_table and then we can operate on it directly.

Quoted 23 lines
Quoted 13 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -0
+
          return 0;

      err_free_st:
-       shmem_free_st(st, filp->f_mapping, false, false); +       shmem_free_st_table(st, filp->f_mapping, false, false); +       kfree(st);
+
         return err;
   }
   @@ -249,16 +249,29 @@ static void i915_ttm_tt_shmem_unpopulate(struct ttm_tt *ttm)
   {

Quoted 8 lines

         struct i915_ttm_tt *i915_tt = container_of(ttm, typeof(*i915_tt), ttm);
         bool backup = ttm->page_flags & TTM_TT_FLAG_SWAPPED; +       struct sg_table *st = &i915_tt->cached_rsgt.table; -       dma_unmap_sg(i915_tt->dev, i915_tt->cached_st->sgl, -                    i915_tt->cached_st->nents,
-                    DMA_BIDIRECTIONAL);
+       if (st->sgl)

Can we ever hit this? I would have presumed not? Below also.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Yes, here's where we typically free the scatterlist.

What I meant to say: can the above ever not be true? i.e sgl == NULL

Hm, Yes I think it can. If we're populating a non-shmem ttm tt, that sg-list is, IIRC allocated lazily on first use. Although I haven't analyzed in detail whether it can actually be populated and then not lazily allocated under the same lock.

Oh right. I guess we could maybe drop the check in the shmem part?

Ah yes, that should be safe. Will do that. Thanks.

/Thomas

Quoted 3 lines
Quoted 3 lines
#8 lore raw

PATCH v2 2/3 drm/i915: Update error capture code to avoid using the current vma state

In reply to Thomas Hellström

With asynchronous migrations, the vma state may be several migrations ahead of the state that matches the request we're capturing. Address that by introducing an i915_vma_snapshot structure that can be used to snapshot relevant state at request submission. In order to make sure we access the correct memory, the snapshots take references on relevant sg-tables and memory regions.

Also move the capture list allocation out of the fence signaling critical path and use the CONFIG_DRM_I915_CAPTURE_ERROR define to avoid compiling in members and functions used for error capture when they're not used.

Finally, correct lockdep annotation would reveal that error capture is typically done in the fence signalling critical path. Alter the error capture memory allocation mode accordingly.

---
 drivers/gpu/drm/i915/Makefile                 |   1 +
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    | 135 ++++++++++---
 drivers/gpu/drm/i915/gt/intel_engine_cs.c     |   8 +-
 .../drm/i915/gt/intel_execlists_submission.c  |   2 +-
 drivers/gpu/drm/i915/i915_gpu_error.c         | 180 +++++++++++++-----
 drivers/gpu/drm/i915/i915_request.c           |  63 ++++--
 drivers/gpu/drm/i915/i915_request.h           |  18 +-
 drivers/gpu/drm/i915/i915_vma_snapshot.c      | 137 +++++++++++++
 drivers/gpu/drm/i915/i915_vma_snapshot.h      | 112 +++++++++++
 9 files changed, 558 insertions(+), 98 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_vma_snapshot.c
 create mode 100644 drivers/gpu/drm/i915/i915_vma_snapshot.h
drivers/gpu/drm/i915/Makefile +1 -0
index 467872cca027..2424c19cd0bc 100644
@@ -173,6 +173,7 @@ i915-y += \
 	  i915_trace_points.o \
 	  i915_ttm_buddy_manager.o \
 	  i915_vma.o \
+	  i915_vma_snapshot.o \
 	  intel_wopcm.o
 
 # general-purpose microcontroller (GuC) support
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +112 -23

202 lines not on this page · raw message

drivers/gpu/drm/i915/gt/intel_engine_cs.c +6 -2
index ff6753ccb129..61e44185990a 100644
@@ -1676,14 +1676,18 @@ static void intel_engine_print_registers(struct intel_engine_cs *engine,
 
 static void print_request_ring(struct drm_printer *m, struct i915_request *rq)
 {
+	struct i915_vma_snapshot *vsnap = &rq->batch_snapshot;
 	void *ring;
 	int size;
 
+	if (!i915_vma_snapshot_present(vsnap))
+		vsnap = NULL;
+
 	drm_printf(m,
 		   "[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]:\n",
 		   rq->head, rq->postfix, rq->tail,
-		   rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
-		   rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
+		   vsnap ? upper_32_bits(vsnap->gtt_offset) : ~0u,
+		   vsnap ? lower_32_bits(vsnap->gtt_offset) : ~0u);
 
 	size = rq->tail - rq->head;
 	if (rq->tail < rq->head)
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +1 -1
index bedb80057046..620c7a262ad0 100644
@@ -2186,7 +2186,7 @@ struct execlists_capture {
 static void execlists_capture_work(struct work_struct *work)
 {
 	struct execlists_capture *cap = container_of(work, typeof(*cap), work);
-	const gfp_t gfp = GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN;
+	const gfp_t gfp = GFP_NOWAIT | __GFP_RETRY_MAYFAIL | __GFP_NOWARN;
 	struct intel_engine_cs *engine = cap->rq->engine;
 	struct intel_gt_coredump *gt = cap->error->gt;
 	struct intel_engine_capture_vma *vma;
drivers/gpu/drm/i915/i915_gpu_error.c +130 -50

321 lines not on this page · raw message

drivers/gpu/drm/i915/i915_request.c +46 -17

105 lines not on this page · raw message

drivers/gpu/drm/i915/i915_request.h +13 -5
index dc359242d1ae..f439bf968517 100644
@@ -40,6 +40,7 @@
 #include "i915_scheduler.h"
 #include "i915_selftest.h"
 #include "i915_sw_fence.h"
+#include "i915_vma_snapshot.h"
 
 #include <uapi/drm/i915_drm.h>
 
@@ -48,11 +49,15 @@ struct drm_i915_gem_object;
 struct drm_printer;
 struct i915_request;
 
+#ifdef CONFIG_DRM_I915_CAPTURE_ERROR
 struct i915_capture_list {
+	struct i915_vma_snapshot *vma_snapshot;
 	struct i915_capture_list *next;
-	struct i915_vma *vma;
 };
 
+void i915_request_free_capture_list(struct i915_capture_list *capture);
+#endif
+
 #define RQ_TRACE(rq, fmt, ...) do {					\
 	const struct i915_request *rq__ = (rq);				\
 	ENGINE_TRACE(rq__->engine, "fence %llx:%lld, current %d " fmt,	\
@@ -289,10 +294,12 @@ struct i915_request {
 	/** Preallocate space in the ring for the emitting the request */
 	u32 reserved_space;
 
-	/** Batch buffer related to this request if any (used for
-	 * error state dump only).
-	 */
-	struct i915_vma *batch;
+	/** Batch buffer pointer for selftest internal use. */
+	I915_SELFTEST_DECLARE(struct i915_vma *batch);
+
+	struct i915_vma_snapshot batch_snapshot;
+
+#ifdef CONFIG_DRM_I915_CAPTURE_ERROR
 	/**
 	 * Additional buffers requested by userspace to be captured upon
 	 * a GPU hang. The vma/obj on this list are protected by their
@@ -300,6 +307,7 @@ struct i915_request {
 	 * on the active_list (of their final request).
 	 */
 	struct i915_capture_list *capture_list;
+#endif
 
 	/** Time at which this request was emitted, in jiffies. */
 	unsigned long emitted_jiffies;
drivers/gpu/drm/i915/i915_vma_snapshot.c new file +137 -0

137 lines not on this page · raw message

drivers/gpu/drm/i915/i915_vma_snapshot.h new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.31.1
#9 lore raw

Re: [PATCH v2 2/3] drm/i915: Update error capture code to avoid using the current vma state

Thank you for the patch! Yet something to improve:

Hi "Thomas,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on drm-tip/drm-tip]
[cannot apply to drm-intel/for-linux-next drm-exynos/exynos-drm-next drm/drm-next tegra-drm/drm/tegra/for-next airlied/drm-next v5.15-rc7 next-20211027] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Thomas-Hellstr-m/Prepare-error-capture-for-asynchronous-migration/20211027-185501
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: i386-randconfig-s001-20211027 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.4-dirty
        # https://github.com/0day-ci/linux/commit/565a7c79aff3eb84fffc704407b376e939360857
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Thomas-Hellstr-m/Prepare-error-capture-for-asynchronous-migration/20211027-185501
        git checkout 565a7c79aff3eb84fffc704407b376e939360857
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386 

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/gpu/drm/i915/i915_request.c: In function 'i915_fence_release':

>> drivers/gpu/drm/i915/i915_request.c:116:2: error: implicit declaration of function 'i915_request_free_capture_list' [-Werror=implicit-function-declaration]
     116 |  i915_request_free_capture_list(fetch_and_zero(&rq->capture_list));
         |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   In file included from drivers/gpu/drm/i915/i915_active_types.h:18,
                    from drivers/gpu/drm/i915/gt/intel_context_types.h:15,
                    from drivers/gpu/drm/i915/gem/i915_gem_context_types.h:20,
                    from drivers/gpu/drm/i915/gem/i915_gem_context.h:10,
                    from drivers/gpu/drm/i915/i915_request.c:33:
>> drivers/gpu/drm/i915/i915_request.c:116:51: error: 'struct i915_request' has no member named 'capture_list'
     116 |  i915_request_free_capture_list(fetch_and_zero(&rq->capture_list));
         |                                                   ^~
   drivers/gpu/drm/i915/i915_utils.h:199:10: note: in definition of macro 'fetch_and_zero'
     199 |  typeof(*ptr) __T = *(ptr);     \
         |          ^~~
>> drivers/gpu/drm/i915/i915_request.c:116:51: error: 'struct i915_request' has no member named 'capture_list'
     116 |  i915_request_free_capture_list(fetch_and_zero(&rq->capture_list));
         |                                                   ^~
   drivers/gpu/drm/i915/i915_utils.h:199:23: note: in definition of macro 'fetch_and_zero'
     199 |  typeof(*ptr) __T = *(ptr);     \
         |                       ^~~
>> drivers/gpu/drm/i915/i915_request.c:116:51: error: 'struct i915_request' has no member named 'capture_list'
     116 |  i915_request_free_capture_list(fetch_and_zero(&rq->capture_list));
         |                                                   ^~
   drivers/gpu/drm/i915/i915_utils.h:200:4: note: in definition of macro 'fetch_and_zero'
     200 |  *(ptr) = (typeof(*ptr))0;     \
         |    ^~~
>> drivers/gpu/drm/i915/i915_request.c:116:51: error: 'struct i915_request' has no member named 'capture_list'
     116 |  i915_request_free_capture_list(fetch_and_zero(&rq->capture_list));
         |                                                   ^~
   drivers/gpu/drm/i915/i915_utils.h:200:20: note: in definition of macro 'fetch_and_zero'
     200 |  *(ptr) = (typeof(*ptr))0;     \
         |                    ^~~

cc1: some warnings being treated as errors

vim +/i915_request_free_capture_list +116 drivers/gpu/drm/i915/i915_request.c

108
109 static void i915_fence_release(struct dma_fence *fence)
110 {
111 struct i915_request *rq = to_request(fence);
112
113 GEM_BUG_ON(rq->guc_prio != GUC_PRIO_INIT &&
114 rq->guc_prio != GUC_PRIO_FINI);
115

 > 116		i915_request_free_capture_list(fetch_and_zero(&rq->capture_list));

117 if (i915_vma_snapshot_present(&rq->batch_snapshot))
118 i915_vma_snapshot_put_onstack(&rq->batch_snapshot);
119
120 /*
121 * The request is put onto a RCU freelist (i.e. the address
122 * is immediately reused), mark the fences as being freed now.
123 * Otherwise the debugobjects for the fences are only marked as
124 * freed when the slab cache itself is freed, and so we would get
125 * caught trying to reuse dead objects.
126 */
127 i915_sw_fence_fini(&rq->submit);
128 i915_sw_fence_fini(&rq->semaphore);
129
130 /*
131 * Keep one request on each engine for reserved use under mempressure,
132 * do not use with virtual engines as this really is only needed for
133 * kernel contexts.
134 */
135 if (!intel_engine_is_virtual(rq->engine) &&
136 !cmpxchg(&rq->engine->request_pool, NULL, rq)) {
137 intel_context_put(rq->context);
138 return;
139 }
140
141 intel_context_put(rq->context);
142
143 kmem_cache_free(slab_requests, rq);
144 }
145

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#10 lore raw

PATCH v2 3/3 drm/i915: Initial introduction of vma resources

In reply to Thomas Hellström

From: Thomas Hellström <[email protected]>

The vma resource are needed for asynchronous bind management and are similar to TTM resources. They contain the data needed for asynchronous unbinding (typically the vm range, any backend private information and a means to do refcounting and to hold the unbinding for error capture).

When a vma is bound, a vma resource is created and attached to the vma, and on async unbinding it is detached from the vma, and instead the vm records the fence marking unbind complete. This fence needs to be waited on before we can bind the same region again, so either the fence can be recorded for this particular range only, using an interval tree, or as a simpler approach, for the whole vm. The latter means no binding can take place on a vm until all detached vma resources scheduled for unbind are signaled. With an interval tree fence recording, the interval tree needs to be searched for fences to be signaled before binding can take place.

But most of that is for later, this patch only introduces stub vma resources without unbind capability and the fences of which are waited for sync during unbinding. At this point we're interested in the hold capability as a POC for error capture. Note that the current sync waiting at unbind time is done uninterruptible, but that's OK since we're only ever waiting during error capture, and in that case there's very little gpu activity (if any) that can stall.

v2:
- Fix the mock gtt selftest to bind with vma resources.
- Update a code comment.
- Account for rebinding the same vma with different I915_VMA_*_BIND flags

---
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    |   2 +-
 drivers/gpu/drm/i915/i915_vma.c               | 201 +++++++++++++++++-
 drivers/gpu/drm/i915/i915_vma.h               |  20 +-
 drivers/gpu/drm/i915/i915_vma_snapshot.c      |  14 +-
 drivers/gpu/drm/i915/i915_vma_snapshot.h      |   2 +-
 drivers/gpu/drm/i915/i915_vma_types.h         |   5 +
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c |  99 +++++----
 7 files changed, 284 insertions(+), 59 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1 -1
index 301eb58bebd1..69915c00ce18 100644
@@ -1376,7 +1376,7 @@ eb_relocate_entry(struct i915_execbuffer *eb,
 		    GRAPHICS_VER(eb->i915) == 6) {
 			err = i915_vma_bind(target->vma,
 					    target->vma->obj->cache_level,
-					    PIN_GLOBAL, NULL);
+					    PIN_GLOBAL, NULL, NULL);
 			if (err)
 				return err;
 		}
drivers/gpu/drm/i915/i915_vma.c +195 -6

288 lines not on this page · raw message

drivers/gpu/drm/i915/i915_vma.h +19 -1
index 648dbe744c96..aa13d0d5bb91 100644
@@ -206,7 +206,8 @@ struct i915_vma_work *i915_vma_work(void);
 int i915_vma_bind(struct i915_vma *vma,
 		  enum i915_cache_level cache_level,
 		  u32 flags,
-		  struct i915_vma_work *work);
+		  struct i915_vma_work *work,
+		  struct i915_vma_resource *vma_res);
 
 bool i915_gem_valid_gtt_space(struct i915_vma *vma, unsigned long color);
 bool i915_vma_misplaced(const struct i915_vma *vma,
@@ -433,7 +434,24 @@ static inline int i915_vma_sync(struct i915_vma *vma)
 	return i915_active_wait(&vma->active);
 }
 
+bool i915_vma_resource_hold(struct i915_vma_resource *vma_res,
+			    bool *lockdep_cookie);
+
+void i915_vma_resource_unhold(struct i915_vma_resource *vma_res,
+			      bool lockdep_cookie);
+
+void i915_vma_resource_put(struct i915_vma_resource *vma_res);
+
+struct i915_vma_resource *i915_vma_get_current_resource(struct i915_vma *vma);
+
+struct i915_vma_resource *i915_vma_resource_alloc(void);
+
 void i915_vma_module_exit(void);
 int i915_vma_module_init(void);
 
+#ifdef CONFIG_DRM_I915_SELFTEST
+void i915_vma_resource_init(struct i915_vma_resource *vma_res,
+			    struct i915_vma *vma);
+#endif
+
 #endif
drivers/gpu/drm/i915/i915_vma_snapshot.c +4 -10
index 44985d600f96..b4ee8220df85 100644
@@ -36,7 +36,7 @@ void i915_vma_snapshot_init(struct i915_vma_snapshot *vsnap,
 	if (vma->obj->mm.region)
 		vsnap->mr = intel_memory_region_get(vma->obj->mm.region);
 	kref_init(&vsnap->kref);
-	vsnap->vma_resource = &vma->active;
+	vsnap->vma_resource = i915_vma_get_current_resource(vma);
 	vsnap->onstack = false;
 	vsnap->present = true;
 }
@@ -63,6 +63,7 @@ static void vma_snapshot_release(struct kref *ref)
 		container_of(ref, typeof(*vsnap), kref);
 
 	vsnap->present = false;
+	i915_vma_resource_put(vsnap->vma_resource);
 	if (vsnap->mr)
 		intel_memory_region_put(vsnap->mr);
 	if (vsnap->pages_rsgt)
@@ -112,12 +113,7 @@ void i915_vma_snapshot_put_onstack(struct i915_vma_snapshot *vsnap)
 bool i915_vma_snapshot_resource_pin(struct i915_vma_snapshot *vsnap,
 				    bool *lockdep_cookie)
 {
-	bool pinned = i915_active_acquire_if_busy(vsnap->vma_resource);
-
-	if (pinned)
-		*lockdep_cookie = dma_fence_begin_signalling();
-
-	return pinned;
+	return i915_vma_resource_hold(vsnap->vma_resource, lockdep_cookie);
 }
 
 /**
@@ -131,7 +127,5 @@ bool i915_vma_snapshot_resource_pin(struct i915_vma_snapshot *vsnap,
 void i915_vma_snapshot_resource_unpin(struct i915_vma_snapshot *vsnap,
 				      bool lockdep_cookie)
 {
-	dma_fence_end_signalling(lockdep_cookie);
-
-	return i915_active_release(vsnap->vma_resource);
+	i915_vma_resource_unhold(vsnap->vma_resource, lockdep_cookie);
 }
drivers/gpu/drm/i915/i915_vma_snapshot.h +1 -1
index 940581df4622..d083b6bf1b11 100644
@@ -49,7 +49,7 @@ struct i915_vma_snapshot {
 	struct i915_refct_sgt *pages_rsgt;
 	struct intel_memory_region *mr;
 	struct kref kref;
-	struct i915_active *vma_resource;
+	struct i915_vma_resource *vma_resource;
 	u32 page_sizes;
 	bool onstack:1;
 	bool present:1;
drivers/gpu/drm/i915/i915_vma_types.h +5 -0
index 80e93bf00f2e..14d20ac5350c 100644
@@ -95,6 +95,8 @@ enum i915_cache_level;
  *
  */
 
+struct i915_vma_resource;
+
 struct intel_remapped_plane_info {
 	/* in gtt pages */
 	u32 offset;
@@ -284,6 +286,9 @@ struct i915_vma {
 	struct list_head evict_link;
 
 	struct list_head closed_link;
+
+	/** The async vma resource. Protected by the vm_mutex */
+	struct i915_vma_resource *resource;
 };
 
 #endif
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +59 -40

153 lines not on this page · raw message

Signature · 1 line
2.31.1
#11 lore raw

Re: [Intel-gfx] [PATCH v2 3/3] drm/i915: Initial introduction of vma resources

Thank you for the patch! Yet something to improve:

Hi "Thomas,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on drm-tip/drm-tip]
[cannot apply to drm-intel/for-linux-next drm-exynos/exynos-drm-next drm/drm-next tegra-drm/drm/tegra/for-next airlied/drm-next v5.15-rc7 next-20211027] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Thomas-Hellstr-m/Prepare-error-capture-for-asynchronous-migration/20211027-185501
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: i386-defconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/ce3de63c87b40e04e9a9960549435085aa55fb27
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Thomas-Hellstr-m/Prepare-error-capture-for-asynchronous-migration/20211027-185501
        git checkout ce3de63c87b40e04e9a9960549435085aa55fb27
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/gpu/drm/i915/i915_vma.c: In function 'i915_vma_bind':

>> drivers/gpu/drm/i915/i915_vma.c:445:3: error: implicit declaration of function 'i915_vma_resource_init'; did you mean 'i915_vma_resource_put'? [-Werror=implicit-function-declaration]
     445 |   i915_vma_resource_init(vma_res, vma);
         |   ^~~~~~~~~~~~~~~~~~~~~~
         |   i915_vma_resource_put
   drivers/gpu/drm/i915/i915_vma.c: At top level:
   drivers/gpu/drm/i915/i915_vma.c:1502:1: error: conflicting types for 'i915_vma_resource_init' [-Werror]
    1502 | i915_vma_resource_init(struct i915_vma_resource *vma_res,
         | ^~~~~~~~~~~~~~~~~~~~~~
>> drivers/gpu/drm/i915/i915_vma.c:1502:1: error: static declaration of 'i915_vma_resource_init' follows non-static declaration
   drivers/gpu/drm/i915/i915_vma.c:445:3: note: previous implicit declaration of 'i915_vma_resource_init' was here
     445 |   i915_vma_resource_init(vma_res, vma);
         |   ^~~~~~~~~~~~~~~~~~~~~~
>> drivers/gpu/drm/i915/i915_vma.c:1502:1: error: 'i915_vma_resource_init' defined but not used [-Werror=unused-function]
    1502 | i915_vma_resource_init(struct i915_vma_resource *vma_res,
         | ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

vim +445 drivers/gpu/drm/i915/i915_vma.c

384
385 /**
386 * i915_vma_bind - Sets up PTEs for an VMA in it's corresponding address space.
387 * @vma: VMA to map
388 * @cache_level: mapping cache level
389 * @flags: flags like global or local mapping
390 * @work: preallocated worker for allocating and binding the PTE
391 * @vma_res: pointer to a preallocated vma resource. The resource is either
392 * consumed or freed.
393 *
394 * DMA addresses are taken from the scatter-gather table of this object (or of
395 * this VMA in case of non-default GGTT views) and PTE entries set up.
396 * Note that DMA addresses are also the only part of the SG table we care about.
397 */
398 int i915_vma_bind(struct i915_vma *vma,

   399			  enum i915_cache_level cache_level,
   400			  u32 flags,
   401			  struct i915_vma_work *work,
   402			  struct i915_vma_resource *vma_res)
   403	{
   404		u32 bind_flags;
   405		u32 vma_flags;
   406	
   407		GEM_BUG_ON(!drm_mm_node_allocated(&vma->node));
   408		GEM_BUG_ON(vma->size > vma->node.size);
   409	
   410		if (GEM_DEBUG_WARN_ON(range_overflows(vma->node.start,
   411						      vma->node.size,
   412						      vma->vm->total))) {
   413			kfree(vma_res);
   414			return -ENODEV;
   415		}
   416	
   417		if (GEM_DEBUG_WARN_ON(!flags)) {
   418			kfree(vma_res);
   419			return -EINVAL;
   420		}
   421	
   422		bind_flags = flags;
   423		bind_flags &= I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND;
   424	
   425		vma_flags = atomic_read(&vma->flags);
   426		vma_flags &= I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND;
   427	
   428		bind_flags &= ~vma_flags;
   429		if (bind_flags == 0) {
   430			kfree(vma_res);
   431			return 0;
   432		}
   433	
   434		GEM_BUG_ON(!vma->pages);
   435	
   436		if (!i915_vma_is_pinned(vma))
   437			lockdep_assert_held(&vma->vm->mutex);
   438	
   439		if ((vma->resource) || !vma_res) {
   440			/* Rebinding with an additional I915_VMA_*_BIND */
   441			GEM_WARN_ON(!vma_flags);
   442			kfree(vma_res);
   443		} else {
   444			lockdep_assert_held(&vma->vm->mutex);
 > 445			i915_vma_resource_init(vma_res, vma);

446 vma->resource = vma_res;
447 }
448 trace_i915_vma_bind(vma, bind_flags);
449 if (work && bind_flags & vma->vm->bind_async_flags) {
450 struct dma_fence *prev;
451
452 work->vma = vma;
453 work->cache_level = cache_level;
454 work->flags = bind_flags;
455
456 /*
457 * Note we only want to chain up to the migration fence on
458 * the pages (not the object itself). As we don't track that,
459 * yet, we have to use the exclusive fence instead.
460 *
461 * Also note that we do not want to track the async vma as
462 * part of the obj->resv->excl_fence as it only affects
463 * execution and not content or object's backing store lifetime.
464 */
465 prev = i915_active_set_exclusive(&vma->active, &work->base.dma);
466 if (prev) {
467 __i915_sw_fence_await_dma_fence(&work->base.chain,
468 prev,
469 &work->cb);
470 dma_fence_put(prev);
471 }
472
473 work->base.dma.error = 0; /* enable the queue_work() */
474
475 if (vma->obj) {
476 __i915_gem_object_pin_pages(vma->obj);
477 work->pinned = i915_gem_object_get(vma->obj);
478 }
479 } else {
480 vma->ops->bind_vma(vma->vm, NULL, vma, cache_level, bind_flags);
481 }
482
483 atomic_or(bind_flags, &vma->flags);
484 return 0;
485 }
486

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#12 lore raw

[Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Prepare error capture for asynchronous migration (rev2)

In reply to Thomas Hellström
== Series Details ==

== Series Details ==

Series: Prepare error capture for asynchronous migration (rev2)
URL : https://patchwork.freedesktop.org/series/96281/
State : warning

== Summary ==

$ dim checkpatch origin/drm-tip
bf0df3812af8 drm/i915: Introduce refcounted sg-tables
69d21354f04a drm/i915: Update error capture code to avoid using the current vma state
-:803: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating?
#803: 
new file mode 100644

total: 0 errors, 1 warnings, 0 checks, 958 lines checked
ff852d0fa9df drm/i915: Initial introduction of vma resources
-:144: CHECK:UNNECESSARY_PARENTHESES: Unnecessary parentheses around 'vma->resource' #144: FILE: drivers/gpu/drm/i915/i915_vma.c:439:
+ if ((vma->resource) || !vma_res) {

-:564: CHECK:LINE_SPACING: Please don't use multiple blank lines #564: FILE: drivers/gpu/drm/i915/selftests/i915_gem_gtt.c:1493:

+

total: 0 errors, 0 warnings, 2 checks, 543 lines checked

#13 lore raw

[Intel-gfx] ✓ Fi.CI.BAT: success for Prepare error capture for asynchronous migration (rev2)

In reply to Thomas Hellström
== Series Details ==

== Series Details ==

Series: Prepare error capture for asynchronous migration (rev2)
URL : https://patchwork.freedesktop.org/series/96281/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_10796 -> Patchwork_21460
====================================================

Summary
-------

**SUCCESS**

No regressions found.

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

Participating hosts (39 -> 33)
------------------------------

Missing (6): bat-dg1-6 bat-dg1-5 fi-bsw-cyan fi-icl-u2 bat-adlp-4 fi-pnv-d510

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

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

### IGT changes ###

#### Issues hit ####

* igt@debugfs_test@read_all_entries:
- fi-apl-guc: [PASS][1] -> [DMESG-WARN][2] ([i915#1610])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/fi-apl-guc/igt@debugfs_test@read_all_entries.html
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/fi-apl-guc/igt@debugfs_test@read_all_entries.html

* igt@i915_selftest@live@hangcheck:
- fi-snb-2600: [PASS][3] -> [INCOMPLETE][4] ([i915#3921])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/fi-snb-2600/igt@i915_selftest@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/fi-snb-2600/igt@i915_selftest@[email protected]

* igt@kms_frontbuffer_tracking@basic:
- fi-cml-u2: [PASS][5] -> [DMESG-WARN][6] ([i915#4269])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/fi-cml-u2/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/fi-cml-u2/igt@[email protected]

#### Possible fixes ####

* igt@kms_frontbuffer_tracking@basic:
- {fi-hsw-gt1}: [DMESG-WARN][7] ([i915#4290]) -> [PASS][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/fi-hsw-gt1/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/fi-hsw-gt1/igt@[email protected]

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

[i915#1610]: https://gitlab.freedesktop.org/drm/intel/issues/1610
[i915#3921]: https://gitlab.freedesktop.org/drm/intel/issues/3921
[i915#4269]: https://gitlab.freedesktop.org/drm/intel/issues/4269
[i915#4290]: https://gitlab.freedesktop.org/drm/intel/issues/4290

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

* Linux: CI_DRM_10796 -> Patchwork_21460

CI-20190529: 20190529
CI_DRM_10796: c2698ab428a9398c02ef1ee3a03f51608cf97a86 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_6262: d1c793b26e31cc6ae3f9fa3239805a9bbcc749fb @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_21460: ff852d0fa9dfdea483c8c2af48d1ea23e75be309 @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

ff852d0fa9df drm/i915: Initial introduction of vma resources 69d21354f04a drm/i915: Update error capture code to avoid using the current vma state bf0df3812af8 drm/i915: Introduce refcounted sg-tables

== Logs ==

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

#14 lore raw

[Intel-gfx] ✗ Fi.CI.IGT: failure for Prepare error capture for asynchronous migration (rev2)

In reply to Thomas Hellström
== Series Details ==

== Series Details ==

Series: Prepare error capture for asynchronous migration (rev2)
URL : https://patchwork.freedesktop.org/series/96281/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_10796_full -> Patchwork_21460_full
====================================================

Summary
-------

**FAILURE**

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

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

Participating hosts (10 -> 10)
------------------------------

No changes in participating hosts

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

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

### IGT changes ###

#### Possible regressions ####

* igt@gem_softpin@noreloc-s3:
- shard-iclb: [PASS][1] -> [DMESG-WARN][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-iclb5/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb6/igt@[email protected]
- shard-snb: [PASS][3] -> [DMESG-WARN][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-snb2/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-snb5/igt@[email protected]

* igt@i915_pm_rpm@cursor:
- shard-iclb: [PASS][5] -> [INCOMPLETE][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-iclb8/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb4/igt@[email protected]

* igt@kms_flip@single-buffer-flip-vs-dpms-off-vs-modeset@a-edp1:
- shard-tglb: [PASS][7] -> [INCOMPLETE][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-tglb5/igt@kms_flip@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb6/igt@kms_flip@[email protected]

### Piglit changes ###

#### Possible regressions ####

* spec@arb_gpu_shader5@texturegatheroffset@fs-r-0-unorm-2darray-const (NEW):
- pig-kbl-iris: NOTRUN -> [INCOMPLETE][9] +7 similar issues
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/pig-kbl-iris/spec@arb_gpu_shader5@[email protected]

New tests
---------

New tests have been introduced between CI_DRM_10796_full and Patchwork_21460_full:

### New Piglit tests (8) ###

* spec@arb_gpu_shader5@texturegather@fs-r-0-unorm-2darray:
- Statuses : 1 incomplete(s)
- Exec time: [0.0] s

* spec@arb_gpu_shader5@texturegather@fs-r-0-unorm-cube:
- Statuses : 1 incomplete(s)
- Exec time: [0.0] s

* spec@arb_gpu_shader5@texturegather@fs-r-0-unorm-cubearray:
- Statuses : 1 incomplete(s)
- Exec time: [0.0] s

* spec@arb_gpu_shader5@texturegatheroffset@fs-r-0-unorm-2d-const:
- Statuses : 1 incomplete(s)
- Exec time: [0.0] s

* spec@arb_gpu_shader5@texturegatheroffset@fs-r-0-unorm-2darray:
- Statuses : 1 incomplete(s)
- Exec time: [0.0] s

* spec@arb_gpu_shader5@texturegatheroffset@fs-r-0-unorm-2darray-const:
- Statuses : 1 incomplete(s)
- Exec time: [0.0] s

* spec@arb_gpu_shader5@texturegatheroffsets@fs-r-0-unorm-2d:
- Statuses : 1 incomplete(s)
- Exec time: [0.0] s

* spec@arb_gpu_shader5@texturegatheroffsets@fs-r-0-unorm-2darray:
- Statuses : 1 incomplete(s)
- Exec time: [0.0] s

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

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

### IGT changes ###

#### Issues hit ####

* igt@feature_discovery@psr2:
- shard-iclb: [PASS][10] -> [SKIP][11] ([i915#658])
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-iclb2/igt@[email protected]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb8/igt@[email protected]

* igt@gem_exec_fair@basic-none-share@rcs0:
- shard-apl: [PASS][12] -> [SKIP][13] ([fdo#109271])
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-apl3/igt@gem_exec_fair@[email protected]
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-apl2/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-none@rcs0:
- shard-glk: [PASS][14] -> [FAIL][15] ([i915#2842])
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-glk7/igt@gem_exec_fair@[email protected]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-glk8/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-none@vcs0:
- shard-apl: [PASS][16] -> [FAIL][17] ([i915#2842])
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-apl2/igt@gem_exec_fair@[email protected]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-apl7/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-pace@rcs0:
- shard-kbl: [PASS][18] -> [SKIP][19] ([fdo#109271]) +1 similar issue
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-kbl7/igt@gem_exec_fair@[email protected]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl3/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-pace@vcs1:
- shard-iclb: NOTRUN -> [FAIL][20] ([i915#2842])
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb1/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-throttle@rcs0:
- shard-tglb: NOTRUN -> [FAIL][21] ([i915#2842])
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb2/igt@gem_exec_fair@[email protected]

* igt@gem_huc_copy@huc-copy:
- shard-kbl: NOTRUN -> [SKIP][22] ([fdo#109271] / [i915#2190])
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl6/igt@[email protected]

* igt@gem_pxp@verify-pxp-stale-ctx-execution:
- shard-tglb: NOTRUN -> [SKIP][23] ([i915#4270]) +1 similar issue
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb2/igt@[email protected]

* igt@gem_workarounds@suspend-resume:
- shard-tglb: [PASS][24] -> [INCOMPLETE][25] ([i915#456]) +1 similar issue
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-tglb6/igt@[email protected]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb7/igt@[email protected]

* igt@gen9_exec_parse@allowed-all:
- shard-skl: [PASS][26] -> [DMESG-WARN][27] ([i915#1436] / [i915#716])
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-skl4/igt@[email protected]
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-skl10/igt@[email protected]

* igt@i915_pm_rpm@gem-execbuf-stress-pc8:
- shard-tglb: NOTRUN -> [SKIP][28] ([fdo#109506] / [i915#2411])
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb2/igt@[email protected]

* igt@i915_query@query-topology-known-pci-ids:
- shard-tglb: NOTRUN -> [SKIP][29] ([fdo#109303])
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb2/igt@[email protected]

* igt@i915_query@query-topology-unsupported:
- shard-tglb: NOTRUN -> [SKIP][30] ([fdo#109302])
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb5/igt@[email protected]

* igt@kms_big_fb@x-tiled-64bpp-rotate-270:
- shard-tglb: NOTRUN -> [SKIP][31] ([fdo#111614]) +2 similar issues
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb5/igt@[email protected]

* igt@kms_big_fb@x-tiled-max-hw-stride-32bpp-rotate-180-async-flip:
- shard-skl: NOTRUN -> [FAIL][32] ([i915#3743])
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-skl1/igt@kms_big_fb@x-tiled-max-hw-stride-32bpp-rotate-180-async-flip.html

* igt@kms_big_fb@y-tiled-16bpp-rotate-0:
- shard-glk: [PASS][33] -> [DMESG-WARN][34] ([i915#118]) +1 similar issue
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-glk5/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-glk4/igt@[email protected]

* igt@kms_big_fb@y-tiled-max-hw-stride-64bpp-rotate-180-hflip:
- shard-kbl: NOTRUN -> [SKIP][35] ([fdo#109271] / [i915#3777])
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl6/igt@[email protected]

* igt@kms_big_fb@yf-tiled-32bpp-rotate-0:
- shard-tglb: NOTRUN -> [SKIP][36] ([fdo#111615]) +4 similar issues
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb2/igt@[email protected]

* igt@kms_ccs@pipe-a-bad-pixel-format-y_tiled_gen12_rc_ccs_cc:
- shard-skl: NOTRUN -> [SKIP][37] ([fdo#109271] / [i915#3886]) +1 similar issue
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-skl1/igt@kms_ccs@pipe-a-bad-pixel-format-y_tiled_gen12_rc_ccs_cc.html

* igt@kms_ccs@pipe-b-random-ccs-data-y_tiled_gen12_mc_ccs:
- shard-kbl: NOTRUN -> [SKIP][38] ([fdo#109271] / [i915#3886]) +6 similar issues
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl4/igt@kms_ccs@pipe-b-random-ccs-data-y_tiled_gen12_mc_ccs.html

* igt@kms_ccs@pipe-c-ccs-on-another-bo-y_tiled_gen12_mc_ccs:
- shard-glk: NOTRUN -> [SKIP][39] ([fdo#109271] / [i915#3886]) +1 similar issue
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-glk7/igt@kms_ccs@pipe-c-ccs-on-another-bo-y_tiled_gen12_mc_ccs.html

* igt@kms_ccs@pipe-c-random-ccs-data-y_tiled_gen12_mc_ccs:
- shard-tglb: NOTRUN -> [SKIP][40] ([i915#3689] / [i915#3886]) +1 similar issue
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb5/igt@kms_ccs@pipe-c-random-ccs-data-y_tiled_gen12_mc_ccs.html

* igt@kms_ccs@pipe-d-bad-rotation-90-yf_tiled_ccs:
- shard-tglb: NOTRUN -> [SKIP][41] ([i915#3689]) +2 similar issues
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb5/igt@kms_ccs@pipe-d-bad-rotation-90-yf_tiled_ccs.html

* igt@kms_ccs@pipe-d-crc-primary-rotation-180-yf_tiled_ccs:
- shard-apl: NOTRUN -> [SKIP][42] ([fdo#109271]) +13 similar issues
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-apl8/igt@kms_ccs@pipe-d-crc-primary-rotation-180-yf_tiled_ccs.html

* igt@kms_chamelium@dp-crc-multiple:
- shard-tglb: NOTRUN -> [SKIP][43] ([fdo#109284] / [fdo#111827]) +4 similar issues
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb2/igt@[email protected]

* igt@kms_chamelium@hdmi-aspect-ratio:
- shard-glk: NOTRUN -> [SKIP][44] ([fdo#109271] / [fdo#111827]) +5 similar issues
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-glk7/igt@[email protected]

* igt@kms_chamelium@hdmi-crc-nonplanar-formats:
- shard-iclb: NOTRUN -> [SKIP][45] ([fdo#109284] / [fdo#111827])
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb3/igt@[email protected]

* igt@kms_color_chamelium@pipe-a-ctm-negative:
- shard-kbl: NOTRUN -> [SKIP][46] ([fdo#109271] / [fdo#111827]) +10 similar issues
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl6/igt@[email protected]

* igt@kms_color_chamelium@pipe-d-ctm-0-25:
- shard-skl: NOTRUN -> [SKIP][47] ([fdo#109271] / [fdo#111827]) +2 similar issues
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-skl1/igt@[email protected]

* igt@kms_color_chamelium@pipe-d-ctm-max:
- shard-apl: NOTRUN -> [SKIP][48] ([fdo#109271] / [fdo#111827])
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-apl8/igt@[email protected]

* igt@kms_content_protection@atomic:
- shard-kbl: NOTRUN -> [TIMEOUT][49] ([i915#1319])
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl4/igt@[email protected]

* igt@kms_content_protection@type1:
- shard-tglb: NOTRUN -> [SKIP][50] ([fdo#111828])
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb5/igt@[email protected]

* igt@kms_cursor_crc@pipe-a-cursor-32x32-sliding:
- shard-tglb: NOTRUN -> [SKIP][51] ([i915#3319])
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb5/igt@[email protected]

* igt@kms_cursor_crc@pipe-b-cursor-512x512-random:
- shard-tglb: NOTRUN -> [SKIP][52] ([fdo#109279] / [i915#3359])
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb5/igt@[email protected]

* igt@kms_cursor_crc@pipe-c-cursor-max-size-offscreen:
- shard-tglb: NOTRUN -> [SKIP][53] ([i915#3359]) +2 similar issues
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb2/igt@[email protected]

* igt@kms_cursor_crc@pipe-c-cursor-suspend:
- shard-kbl: NOTRUN -> [DMESG-WARN][54] ([i915#180]) +2 similar issues
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl4/igt@[email protected]

* igt@kms_cursor_crc@pipe-d-cursor-512x512-sliding:
- shard-glk: NOTRUN -> [SKIP][55] ([fdo#109271]) +31 similar issues
[55]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-glk7/igt@[email protected]

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-atomic:
- shard-tglb: NOTRUN -> [SKIP][56] ([i915#4103]) +1 similar issue
[56]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb2/igt@[email protected]

* igt@kms_cursor_legacy@flip-vs-cursor-atomic:
- shard-skl: [PASS][57] -> [FAIL][58] ([i915#2346]) +1 similar issue
[57]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-skl6/igt@[email protected]
[58]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-skl2/igt@[email protected]

* igt@kms_fbcon_fbt@fbc-suspend:
- shard-apl: [PASS][59] -> [INCOMPLETE][60] ([i915#180] / [i915#1982])
[59]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-apl1/igt@[email protected]
[60]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-apl4/igt@[email protected]

* igt@kms_flip@2x-plain-flip-ts-check-interruptible:
- shard-iclb: NOTRUN -> [SKIP][61] ([fdo#109274])
[61]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb3/igt@[email protected]

* igt@kms_flip@plain-flip-fb-recreate-interruptible@c-edp1:
- shard-skl: [PASS][62] -> [FAIL][63] ([i915#2122]) +3 similar issues
[62]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-skl7/igt@kms_flip@[email protected]
[63]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-skl2/igt@kms_flip@[email protected]

* igt@kms_flip_scaled_crc@flip-32bpp-ytileccs-to-64bpp-ytile:
- shard-iclb: [PASS][64] -> [SKIP][65] ([i915#3701])
[64]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-iclb7/igt@[email protected]
[65]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb2/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-2p-primscrn-spr-indfb-draw-blt:
- shard-iclb: NOTRUN -> [SKIP][66] ([fdo#109280])
[66]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb3/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-2p-scndscrn-pri-indfb-draw-blt:
- shard-skl: NOTRUN -> [SKIP][67] ([fdo#109271]) +51 similar issues
[67]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-skl1/igt@[email protected]

* igt@kms_frontbuffer_tracking@psr-2p-scndscrn-cur-indfb-move:
- shard-tglb: NOTRUN -> [SKIP][68] ([fdo#111825]) +11 similar issues
[68]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb2/igt@[email protected]

* igt@kms_frontbuffer_tracking@psr-rgb101010-draw-mmap-wc:
- shard-kbl: NOTRUN -> [SKIP][69] ([fdo#109271]) +145 similar issues
[69]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl3/igt@[email protected]

* igt@kms_frontbuffer_tracking@psr-suspend:
- shard-tglb: [PASS][70] -> [INCOMPLETE][71] ([i915#2411] / [i915#456])
[70]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-tglb3/igt@[email protected]
[71]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb7/igt@[email protected]

* igt@kms_hdr@bpc-switch-suspend:
- shard-apl: [PASS][72] -> [DMESG-WARN][73] ([i915#180]) +4 similar issues
[72]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-apl3/igt@[email protected]
[73]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-apl2/igt@[email protected]

* igt@kms_pipe_crc_basic@read-crc-pipe-d-frame-sequence:
- shard-kbl: NOTRUN -> [SKIP][74] ([fdo#109271] / [i915#533])
[74]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl4/igt@[email protected]

* igt@kms_plane@plane-panning-bottom-right-suspend@pipe-b-planes:
- shard-kbl: [PASS][75] -> [DMESG-WARN][76] ([i915#180])
[75]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-kbl3/igt@kms_plane@[email protected]
[76]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl4/igt@kms_plane@[email protected]

* igt@kms_plane_alpha_blend@pipe-a-constant-alpha-max:
- shard-glk: NOTRUN -> [FAIL][77] ([fdo#108145] / [i915#265])
[77]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-glk7/igt@[email protected]
- shard-apl: NOTRUN -> [FAIL][78] ([fdo#108145] / [i915#265])
[78]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-apl8/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-b-alpha-transparent-fb:
- shard-kbl: NOTRUN -> [FAIL][79] ([i915#265])
[79]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl3/igt@[email protected]
- shard-skl: NOTRUN -> [FAIL][80] ([i915#265])
[80]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-skl1/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-b-constant-alpha-min:
- shard-skl: [PASS][81] -> [FAIL][82] ([fdo#108145] / [i915#265])
[81]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-skl7/igt@[email protected]
[82]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-skl2/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-c-alpha-7efc:
- shard-kbl: NOTRUN -> [FAIL][83] ([fdo#108145] / [i915#265])
[83]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl6/igt@[email protected]

* igt@kms_plane_lowres@pipe-b-tiling-y:
- shard-tglb: NOTRUN -> [SKIP][84] ([i915#3536])
[84]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb2/igt@[email protected]

* igt@kms_plane_lowres@pipe-c-tiling-yf:
- shard-iclb: NOTRUN -> [SKIP][85] ([i915#3536])
[85]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb3/igt@[email protected]

* igt@kms_plane_lowres@pipe-d-tiling-yf:
- shard-tglb: NOTRUN -> [SKIP][86] ([fdo#112054]) +1 similar issue
[86]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb2/igt@[email protected]

* igt@kms_psr2_sf@overlay-plane-update-sf-dmg-area-1:
- shard-kbl: NOTRUN -> [SKIP][87] ([fdo#109271] / [i915#658]) +2 similar issues
[87]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl6/igt@[email protected]
- shard-tglb: NOTRUN -> [SKIP][88] ([i915#2920])
[88]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb2/igt@[email protected]

* igt@kms_psr2_sf@overlay-plane-update-sf-dmg-area-5:
- shard-skl: NOTRUN -> [SKIP][89] ([fdo#109271] / [i915#658])
[89]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-skl1/igt@[email protected]

* igt@kms_psr2_sf@primary-plane-update-sf-dmg-area-5:
- shard-iclb: NOTRUN -> [SKIP][90] ([i915#658])
[90]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb3/igt@[email protected]

* igt@kms_psr@psr2_cursor_plane_onoff:
- shard-tglb: NOTRUN -> [FAIL][91] ([i915#132] / [i915#3467]) +1 similar issue
[91]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb5/igt@kms_psr@psr2_cursor_plane_onoff.html

* igt@kms_psr@psr2_primary_mmap_cpu:
- shard-iclb: [PASS][92] -> [SKIP][93] ([fdo#109441]) +1 similar issue
[92]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-iclb2/igt@kms_psr@psr2_primary_mmap_cpu.html
[93]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb4/igt@kms_psr@psr2_primary_mmap_cpu.html

* igt@kms_psr@psr2_primary_render:
- shard-iclb: NOTRUN -> [SKIP][94] ([fdo#109441])
[94]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb3/igt@kms_psr@psr2_primary_render.html

* igt@kms_universal_plane@universal-plane-gen9-features-pipe-d:
- shard-iclb: NOTRUN -> [SKIP][95] ([fdo#109278])
[95]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb3/igt@[email protected]

* igt@kms_writeback@writeback-check-output:
- shard-kbl: NOTRUN -> [SKIP][96] ([fdo#109271] / [i915#2437])
[96]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl4/igt@[email protected]

* igt@kms_writeback@writeback-fb-id:
- shard-glk: NOTRUN -> [SKIP][97] ([fdo#109271] / [i915#2437])
[97]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-glk7/igt@[email protected]

* igt@nouveau_crc@pipe-b-ctx-flip-detection:
- shard-tglb: NOTRUN -> [SKIP][98] ([i915#2530])
[98]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb5/igt@[email protected]

* igt@prime_nv_test@i915_import_gtt_mmap:
- shard-iclb: NOTRUN -> [SKIP][99] ([fdo#109291])
[99]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb3/igt@prime_nv_test@i915_import_gtt_mmap.html

* igt@sysfs_clients@create:
- shard-kbl: NOTRUN -> [SKIP][100] ([fdo#109271] / [i915#2994])
[100]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl3/igt@[email protected]

* igt@sysfs_clients@fair-0:
- shard-glk: NOTRUN -> [SKIP][101] ([fdo#109271] / [i915#2994])
[101]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-glk7/igt@[email protected]

* igt@sysfs_clients@pidname:
- shard-tglb: NOTRUN -> [SKIP][102] ([i915#2994])
[102]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb5/igt@[email protected]

#### Possible fixes ####

* igt@gem_ctx_shared@q-smoketest-all:
- shard-glk: [DMESG-WARN][103] ([i915#118]) -> [PASS][104]
[103]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-glk6/igt@[email protected]
[104]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-glk6/igt@[email protected]

* igt@gem_exec_fair@basic-none@vcs0:
- shard-kbl: [FAIL][105] ([i915#2842]) -> [PASS][106] +1 similar issue
[105]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-kbl1/igt@gem_exec_fair@[email protected]
[106]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl6/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-none@vecs0:
- shard-iclb: [FAIL][107] ([i915#2842]) -> [PASS][108]
[107]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-iclb3/igt@gem_exec_fair@[email protected]
[108]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb7/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-pace@rcs0:
- shard-tglb: [FAIL][109] ([i915#2842]) -> [PASS][110]
[109]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-tglb1/igt@gem_exec_fair@[email protected]
[110]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb3/igt@gem_exec_fair@[email protected]

* igt@gem_workarounds@suspend-resume:
- shard-apl: [DMESG-WARN][111] ([i915#180]) -> [PASS][112]
[111]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-apl4/igt@[email protected]
[112]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-apl8/igt@[email protected]

* igt@i915_suspend@debugfs-reader:
- shard-tglb: [INCOMPLETE][113] ([i915#456]) -> [PASS][114]
[113]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-tglb7/igt@[email protected]
[114]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb5/igt@[email protected]

* igt@kms_cursor_legacy@2x-long-flip-vs-cursor-legacy:
- shard-glk: [FAIL][115] ([i915#72]) -> [PASS][116]
[115]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-glk5/igt@[email protected]
[116]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-glk3/igt@[email protected]

* igt@kms_cursor_legacy@flip-vs-cursor-toggle:
- shard-iclb: [FAIL][117] ([i915#2346]) -> [PASS][118]
[117]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-iclb7/igt@[email protected]
[118]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-iclb5/igt@[email protected]

* igt@kms_fbcon_fbt@fbc-suspend:
- shard-kbl: [INCOMPLETE][119] ([i915#180] / [i915#636]) -> [PASS][120]
[119]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-kbl6/igt@[email protected]
[120]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl3/igt@[email protected]

* igt@kms_flip@flip-vs-expired-vblank-interruptible@a-edp1:
- shard-skl: [FAIL][121] ([i915#79]) -> [PASS][122]
[121]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-skl4/igt@kms_flip@[email protected]
[122]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-skl10/igt@kms_flip@[email protected]

* igt@kms_flip@modeset-vs-vblank-race-interruptible@b-edp1:
- shard-tglb: [INCOMPLETE][123] -> [PASS][124]
[123]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-tglb8/igt@kms_flip@[email protected]
[124]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-tglb2/igt@kms_flip@[email protected]

* igt@kms_flip@plain-flip-fb-recreate@a-edp1:
- shard-skl: [FAIL][125] ([i915#2122]) -> [PASS][126]
[125]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-skl9/igt@kms_flip@[email protected]
[126]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-skl7/igt@kms_flip@[email protected]

* igt@kms_hdr@bpc-switch-dpms:
- shard-skl: [FAIL][127] ([i915#1188]) -> [PASS][128]
[127]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-skl4/igt@[email protected]
[128]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-skl10/igt@[email protected]

* igt@kms_hdr@bpc-switch-suspend:
- shard-kbl: [DMESG-WARN][129] ([i915#180]) -> [PASS][130] +4 similar issues
[129]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/shard-kbl1/igt@[email protected]
[130]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21460/shard-kbl6/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-a-coverage-7efc:
- shard-skl: [FAIL][131] ([fdo#108145] / [i915#265]) -> [PASS][132]
[131]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10796/

== Logs ==

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