All of lore.kernel.org
 help / color / mirror / Atom feed
From: Karol Herbst <kherbst@redhat.com>
To: dri-devel@lists.freedesktop.org
Cc: Alex Deucher <alexander.deucher@amd.com>,
	Karol Herbst <kherbst@redhat.com>
Subject: [PATCH 4/6] Revert "drm/ttm: use a static ttm_bo_global instance"
Date: Tue, 16 Apr 2019 02:35:21 +0200	[thread overview]
Message-ID: <20190416003523.5069-5-kherbst@redhat.com> (raw)
In-Reply-To: <20190416003523.5069-1-kherbst@redhat.com>

This reverts commit 62b53b37e4b1500d4eb4624a44ad861cf8d3cd18.

Signed-off-by: Karol Herbst <kherbst@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c    | 31 ++++++++-----------------------
 include/drm/ttm/ttm_bo_driver.h | 15 +++++++--------
 2 files changed, 15 insertions(+), 31 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 6941562ef2fa..c0efe4c89baf 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -49,9 +49,6 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj);
  * ttm_global_mutex - protecting the global BO state
  */
 DEFINE_MUTEX(ttm_global_mutex);
-struct ttm_bo_global ttm_bo_glob = {
-	.use_count = 0
-};
 
 static struct attribute ttm_bo_count = {
 	.name = "bo_count",
@@ -1531,35 +1528,22 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj)
 	kfree(glob);
 }
 
-void ttm_bo_global_release(void)
+void ttm_bo_global_release(struct ttm_bo_global *glob)
 {
-	struct ttm_bo_global *glob = &ttm_bo_glob;
-
-	mutex_lock(&ttm_global_mutex);
-	if (--glob->use_count > 0)
-		goto out;
-
 	kobject_del(&glob->kobj);
 	kobject_put(&glob->kobj);
 	ttm_mem_global_release(&ttm_mem_glob);
-out:
-	mutex_unlock(&ttm_global_mutex);
 }
 EXPORT_SYMBOL(ttm_bo_global_release);
 
-int ttm_bo_global_init(void)
+int ttm_bo_global_init(struct ttm_bo_global *glob)
 {
-	struct ttm_bo_global *glob = &ttm_bo_glob;
-	int ret = 0;
+	int ret;
 	unsigned i;
 
-	mutex_lock(&ttm_global_mutex);
-	if (++glob->use_count > 1)
-		goto out;
-
 	ret = ttm_mem_global_init(&ttm_mem_glob);
 	if (ret)
-		goto out;
+		return ret;
 
 	spin_lock_init(&glob->lru_lock);
 	glob->mem_glob = &ttm_mem_glob;
@@ -1568,7 +1552,7 @@ int ttm_bo_global_init(void)
 
 	if (unlikely(glob->dummy_read_page == NULL)) {
 		ret = -ENOMEM;
-		goto out;
+		goto out_no_drp;
 	}
 
 	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
@@ -1580,8 +1564,9 @@ int ttm_bo_global_init(void)
 		&glob->kobj, &ttm_bo_glob_kobj_type, ttm_get_kobj(), "buffer_objects");
 	if (unlikely(ret != 0))
 		kobject_put(&glob->kobj);
-out:
-	mutex_unlock(&ttm_global_mutex);
+	return ret;
+out_no_drp:
+	kfree(glob);
 	return ret;
 }
 EXPORT_SYMBOL(ttm_bo_global_init);
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 26be74939f10..9cec8835b88f 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -398,7 +398,7 @@ struct ttm_bo_driver {
  * @swap_lru: Lru list of buffer objects used for swapping.
  */
 
-extern struct ttm_bo_global {
+struct ttm_bo_global {
 
 	/**
 	 * Constant after init.
@@ -410,9 +410,8 @@ extern struct ttm_bo_global {
 	spinlock_t lru_lock;
 
 	/**
-	 * Protected by ttm_global_mutex.
+	 * Protected by device_list_mutex.
 	 */
-	unsigned int use_count;
 	struct list_head device_list;
 
 	/**
@@ -424,7 +423,7 @@ extern struct ttm_bo_global {
 	 * Internal protection.
 	 */
 	atomic_t bo_count;
-} ttm_bo_glob;
+};
 
 
 #define TTM_NUM_MEM_TYPES 8
@@ -569,8 +568,8 @@ void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem);
 void ttm_bo_mem_put_locked(struct ttm_buffer_object *bo,
 			   struct ttm_mem_reg *mem);
 
-void ttm_bo_global_release(void);
-int ttm_bo_global_init(void);
+void ttm_bo_global_release(struct ttm_bo_global *glob);
+int ttm_bo_global_init(struct ttm_bo_global *glob);
 
 int ttm_bo_device_release(struct ttm_bo_device *bdev);
 
@@ -907,7 +906,7 @@ struct ttm_bo_global_ref {
  */
 static inline int ttm_bo_global_ref_init(struct drm_global_reference *ref)
 {
-	return ttm_bo_global_init();
+	return ttm_bo_global_init(ref->object);
 }
 
 /**
@@ -921,7 +920,7 @@ static inline int ttm_bo_global_ref_init(struct drm_global_reference *ref)
  */
 static inline void ttm_bo_global_ref_release(struct drm_global_reference *ref)
 {
-	ttm_bo_global_release();
+	ttm_bo_global_release(ref->object);
 }
 
 #endif
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2019-04-16  0:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-16  0:35 [PATCH 0/6] Fix crash after reloading a driver using ttm Karol Herbst
2019-04-16  0:35 ` [PATCH 1/6] Revert "drm: Remove drm_global.{c,h} v2" Karol Herbst
2019-04-16  0:35 ` [PATCH 2/6] Revert "drm/ttm: initialize globals during device init (v2)" Karol Herbst
2019-04-16  0:35 ` [PATCH 3/6] Revert "drm/ttm: Fix bo_global and mem_global kfree error" Karol Herbst
2019-04-16  0:35 ` Karol Herbst [this message]
2019-04-16  0:35 ` [PATCH 5/6] Revert "drm/ttm: make the device list mutex static" Karol Herbst
2019-04-16  0:35 ` [PATCH 6/6] Revert "drm/ttm: use a static ttm_mem_global instance" Karol Herbst
2019-04-16  6:38 ` [PATCH 0/6] Fix crash after reloading a driver using ttm Christian König
2019-04-16  9:10   ` Karol Herbst
2019-04-16  9:12     ` Koenig, Christian
2019-04-16 10:54       ` Karol Herbst
2019-04-16 11:06         ` Koenig, Christian
2019-04-16 11:20           ` Karol Herbst
2019-04-16 11:25             ` Christian König
2019-04-16 12:18           ` Daniel Vetter
2019-04-16 12:29             ` Koenig, Christian
2019-04-16 23:09   ` Eric Anholt
2019-04-17  0:10     ` Karol Herbst

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190416003523.5069-5-kherbst@redhat.com \
    --to=kherbst@redhat.com \
    --cc=alexander.deucher@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.