[Intel-gfx,v6,08/17] drm/ttm: use gem vma_node

Submitted by Gerd Hoffmann on Aug. 14, 2019, 5:58 a.m.

Details

Message ID 20190814055827.6hrxj6daovxxnnvw@sirius.home.kraxel.org
State Accepted
Headers show
Series "Series without cover letter" ( rev: 4 3 2 ) in Spice

Browsing this patch as part of:
"Series without cover letter" rev 3 in Spice
<< prev patch [4/5] next patch >>

Commit Message

Gerd Hoffmann Aug. 14, 2019, 5:58 a.m.
> Hi Gerd,
> 
> I've been seeing a regression on Nouveau with recent linux-next releases
> and git bisect points at this commit as the first bad one. If I revert
> it (there's a tiny conflict with a patch that was merged subsequently),
> things are back to normal.
> 
> I think the reason for this issue is that Nouveau doesn't use GEM
> objects for all buffer objects,

That shouldn't be a problem ...

> and even when it uses GEM objects, the
> code will not initialize the GEM object until after the buffer objects
> and the backing TTM objects have been created.

... but the initialization order is.

ttm_bo_uses_embedded_gem_object() assumes gem gets initialized first.

drm_gem_object_init() init calling drm_vma_node_reset() again is
probably the root cause for the breakage.

> I tried to fix that by making sure drm_gem_object_init() gets called by
> Nouveau before ttm_bo_init(), but the changes are fairly involved and I
> was unable to get the GEM reference counting right. I can look into the
> proper fix some more, but it might be worth reverting this patch for
> now to get Nouveau working again.

Changing the order doesn't look hard.  Patch attached (untested, have no
test hardware).  But maybe I missed some detail ...

The other patch attached works around the issue with a flag, to avoid
drm_vma_node_reset() being called twice.

cheers,
  Gerd
From af43f933533140e2df58176a68df0c60ba082273 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Wed, 14 Aug 2019 07:23:31 +0200
Subject: [PATCH 1/2] try unbreak nouveau #1

---
 include/drm/drm_gem.h        | 11 +++++++++++
 drivers/gpu/drm/drm_gem.c    |  6 ++++--
 drivers/gpu/drm/ttm/ttm_bo.c |  3 ++-
 3 files changed, 17 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
index ae693c0666cd..24e8fc58a3e1 100644
--- a/include/drm/drm_gem.h
+++ b/include/drm/drm_gem.h
@@ -297,6 +297,17 @@  struct drm_gem_object {
 	 *
 	 */
 	const struct drm_gem_object_funcs *funcs;
+
+	/**
+	 * @ttm_init: indicate ttm has initialized _resv and vma_node fields.
+	 *
+	 * ttm_bo_uses_embedded_gem_object() assumes gem is
+	 * initialized before ttm, nouveau does it the other way
+	 * around though.
+	 *
+	 * This is a temporary stopgap to handle that case.
+	 */
+	bool ttm_init;
 };
 
 /**
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index afc38cece3f5..0a75d8cf7ac7 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -159,11 +159,13 @@  void drm_gem_private_object_init(struct drm_device *dev,
 	kref_init(&obj->refcount);
 	obj->handle_count = 0;
 	obj->size = size;
-	reservation_object_init(&obj->_resv);
 	if (!obj->resv)
 		obj->resv = &obj->_resv;
 
-	drm_vma_node_reset(&obj->vma_node);
+	if (!obj->ttm_init) {
+		reservation_object_init(&obj->_resv);
+		drm_vma_node_reset(&obj->vma_node);
+	}
 }
 EXPORT_SYMBOL(drm_gem_private_object_init);
 
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 10a861a1690c..83b389fc117e 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -160,7 +160,7 @@  static void ttm_bo_release_list(struct kref *list_kref)
 	ttm_tt_destroy(bo->ttm);
 	atomic_dec(&bo->bdev->glob->bo_count);
 	dma_fence_put(bo->moving);
-	if (!ttm_bo_uses_embedded_gem_object(bo))
+	if (bo->base.ttm_init)
 		reservation_object_fini(&bo->base._resv);
 	mutex_destroy(&bo->wu_mutex);
 	bo->destroy(bo);
@@ -1344,6 +1344,7 @@  int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
 		 */
 		reservation_object_init(&bo->base._resv);
 		drm_vma_node_reset(&bo->base.vma_node);
+		bo->base.ttm_init = true;
 	}
 	atomic_inc(&bo->bdev->glob->bo_count);