Skip to contentSkip to conversation

drm: revert the remaining commits about dma_buf handling

PATCH In review Melissa Wen 4 participants 14 messages Sep 19, 2025 – Sep 22, 2025

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

cover drm: revert the remaining commits about dma_buf handling

Hi all,

I just talked with Thomas that these two patches are preventing amdgpu driver to be unloaded:

modprobe: FATAL: Module amdgpu is in use.

and there is no process using the driver.

We agreed that the best approach now is to completely revert the work done for improving DMA bug handling to avoid any loose ends. With these reverts we are just back to the old behavior and amdgpu loading and unloading will return to normal.

Best Regards,

Melissa

Melissa Wen (2):
Revert "drm/framebuffer: Acquire internal references on GEM handles" Revert "drm/gem: Acquire references on GEM handles for framebuffers"

 drivers/gpu/drm/drm_framebuffer.c | 31 +--------------
 drivers/gpu/drm/drm_gem.c         | 64 +++++--------------------------
 drivers/gpu/drm/drm_internal.h    |  2 -
 include/drm/drm_framebuffer.h     |  7 ----
 4 files changed, 11 insertions(+), 93 deletions(-)
Signature · 1 line
2.47.2
#1 lore raw

PATCH 1/2 Revert "drm/framebuffer: Acquire internal references on GEM handles"

This reverts commit f6bfc9afc7510cb5e6fbe0a17c507917b0120280.

since we are going to revert commit 5307dce878d4 ("drm/gem: Acquire references on GEM handles for framebuffers"), which it was fixing, this commit won't be needed anymore.

---
 drivers/gpu/drm/drm_framebuffer.c            | 31 ++--------------
 drivers/gpu/drm/drm_gem.c                    | 38 ++++++++------------
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 16 +++++----
 drivers/gpu/drm/drm_internal.h               |  2 +-
 include/drm/drm_framebuffer.h                |  7 ----
 5 files changed, 26 insertions(+), 68 deletions(-)
drivers/gpu/drm/drm_framebuffer.c +2 -29
index adbb73f00d68..61a7213f2389 100644
@@ -863,23 +863,11 @@ EXPORT_SYMBOL_FOR_TESTS_ONLY(drm_framebuffer_free);
 int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
 			 const struct drm_framebuffer_funcs *funcs)
 {
-	unsigned int i;
 	int ret;
-	bool exists;
 
 	if (WARN_ON_ONCE(fb->dev != dev || !fb->format))
 		return -EINVAL;
 
-	for (i = 0; i < fb->format->num_planes; i++) {
-		if (drm_WARN_ON_ONCE(dev, fb->internal_flags & DRM_FRAMEBUFFER_HAS_HANDLE_REF(i)))
-			fb->internal_flags &= ~DRM_FRAMEBUFFER_HAS_HANDLE_REF(i);
-		if (fb->obj[i]) {
-			exists = drm_gem_object_handle_get_if_exists_unlocked(fb->obj[i]);
-			if (exists)
-				fb->internal_flags |= DRM_FRAMEBUFFER_HAS_HANDLE_REF(i);
-		}
-	}
-
 	INIT_LIST_HEAD(&fb->filp_head);
 
 	fb->funcs = funcs;
@@ -888,7 +876,7 @@ int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
 	ret = __drm_mode_object_add(dev, &fb->base, DRM_MODE_OBJECT_FB,
 				    false, drm_framebuffer_free);
 	if (ret)
-		goto err;
+		goto out;
 
 	mutex_lock(&dev->mode_config.fb_lock);
 	dev->mode_config.num_fb++;
@@ -896,16 +884,7 @@ int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
 	mutex_unlock(&dev->mode_config.fb_lock);
 
 	drm_mode_object_register(dev, &fb->base);
-
-	return 0;
-
-err:
-	for (i = 0; i < fb->format->num_planes; i++) {
-		if (fb->internal_flags & DRM_FRAMEBUFFER_HAS_HANDLE_REF(i)) {
-			drm_gem_object_handle_put_unlocked(fb->obj[i]);
-			fb->internal_flags &= ~DRM_FRAMEBUFFER_HAS_HANDLE_REF(i);
-		}
-	}
+out:
 	return ret;
 }
 EXPORT_SYMBOL(drm_framebuffer_init);
@@ -982,12 +961,6 @@ EXPORT_SYMBOL(drm_framebuffer_unregister_private);
 void drm_framebuffer_cleanup(struct drm_framebuffer *fb)
 {
 	struct drm_device *dev = fb->dev;
-	unsigned int i;
-
-	for (i = 0; i < fb->format->num_planes; i++) {
-		if (fb->internal_flags & DRM_FRAMEBUFFER_HAS_HANDLE_REF(i))
-			drm_gem_object_handle_put_unlocked(fb->obj[i]);
-	}
 
 	mutex_lock(&dev->mode_config.fb_lock);
 	list_del(&fb->head);
drivers/gpu/drm/drm_gem.c +14 -24
index cbeb76b2124f..09f80a84d61a 100644
@@ -224,34 +224,23 @@ static void drm_gem_object_handle_get(struct drm_gem_object *obj)
 }
 
 /**
- * drm_gem_object_handle_get_if_exists_unlocked - acquire reference on user-space handle, if any
+ * drm_gem_object_handle_get_unlocked - acquire reference on user-space handles
  * @obj: GEM object
  *
- * Acquires a reference on the GEM buffer object's handle. Required to keep
- * the GEM object alive. Call drm_gem_object_handle_put_if_exists_unlocked()
- * to release the reference. Does nothing if the buffer object has no handle.
- *
- * Returns:
- * True if a handle exists, or false otherwise
+ * Acquires a reference on the GEM buffer object's handle. Required
+ * to keep the GEM object alive. Call drm_gem_object_handle_put_unlocked()
+ * to release the reference.
  */
-bool drm_gem_object_handle_get_if_exists_unlocked(struct drm_gem_object *obj)
+void drm_gem_object_handle_get_unlocked(struct drm_gem_object *obj)
 {
 	struct drm_device *dev = obj->dev;
 
 	guard(mutex)(&dev->object_name_lock);
 
-	/*
-	 * First ref taken during GEM object creation, if any. Some
-	 * drivers set up internal framebuffers with GEM objects that
-	 * do not have a GEM handle. Hence, this counter can be zero.
-	 */
-	if (!obj->handle_count)
-		return false;
-
+	drm_WARN_ON(dev, !obj->handle_count); /* first ref taken in create-tail helper */
 	drm_gem_object_handle_get(obj);
-
-	return true;
 }
+EXPORT_SYMBOL(drm_gem_object_handle_get_unlocked);
 
 /**
  * drm_gem_object_handle_free - release resources bound to userspace handles
@@ -284,7 +273,7 @@ static void drm_gem_object_exported_dma_buf_free(struct drm_gem_object *obj)
 }
 
 /**
- * drm_gem_object_handle_put_unlocked - releases reference on user-space handle
+ * drm_gem_object_handle_put_unlocked - releases reference on user-space handles
  * @obj: GEM object
  *
  * Releases a reference on the GEM buffer object's handle. Possibly releases
@@ -295,14 +284,14 @@ void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)
 	struct drm_device *dev = obj->dev;
 	bool final = false;
 
-	if (drm_WARN_ON(dev, READ_ONCE(obj->handle_count) == 0))
+	if (WARN_ON(READ_ONCE(obj->handle_count) == 0))
 		return;
 
 	/*
-	 * Must bump handle count first as this may be the last
-	 * ref, in which case the object would disappear before
-	 * we checked for a name.
-	 */
+	* Must bump handle count first as this may be the last
+	* ref, in which case the object would disappear before we
+	* checked for a name
+	*/
 
 	mutex_lock(&dev->object_name_lock);
 	if (--obj->handle_count == 0) {
@@ -315,6 +304,7 @@ void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)
 	if (final)
 		drm_gem_object_put(obj);
 }
+EXPORT_SYMBOL(drm_gem_object_handle_put_unlocked);
 
 /*
  * Called at device or object close to release the file's
drivers/gpu/drm/drm_gem_framebuffer_helper.c +9 -7
index 4bc89d33df59..e364fa36ee36 100644
@@ -101,7 +101,7 @@ void drm_gem_fb_destroy(struct drm_framebuffer *fb)
 	unsigned int i;
 
 	for (i = 0; i < fb->format->num_planes; i++)
-		drm_gem_object_put(fb->obj[i]);
+		drm_gem_object_handle_put_unlocked(fb->obj[i]);
 
 	drm_framebuffer_cleanup(fb);
 	kfree(fb);
@@ -179,8 +179,10 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
 		if (!objs[i]) {
 			drm_dbg_kms(dev, "Failed to lookup GEM object\n");
 			ret = -ENOENT;
-			goto err_gem_object_put;
+			goto err_gem_object_handle_put_unlocked;
 		}
+		drm_gem_object_handle_get_unlocked(objs[i]);
+		drm_gem_object_put(objs[i]);
 
 		min_size = (height - 1) * mode_cmd->pitches[i]
 			 + drm_format_info_min_pitch(info, i, width)
@@ -190,22 +192,22 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
 			drm_dbg_kms(dev,
 				    "GEM object size (%zu) smaller than minimum size (%u) for plane %d\n",
 				    objs[i]->size, min_size, i);
-			drm_gem_object_put(objs[i]);
+			drm_gem_object_handle_put_unlocked(objs[i]);
 			ret = -EINVAL;
-			goto err_gem_object_put;
+			goto err_gem_object_handle_put_unlocked;
 		}
 	}
 
 	ret = drm_gem_fb_init(dev, fb, info, mode_cmd, objs, i, funcs);
 	if (ret)
-		goto err_gem_object_put;
+		goto err_gem_object_handle_put_unlocked;
 
 	return 0;
 
-err_gem_object_put:
+err_gem_object_handle_put_unlocked:
 	while (i > 0) {
 		--i;
-		drm_gem_object_put(objs[i]);
+		drm_gem_object_handle_put_unlocked(objs[i]);
 	}
 	return ret;
 }
drivers/gpu/drm/drm_internal.h +1 -1
index 5a3bed48ab1f..ec1bf58e5714 100644
@@ -163,7 +163,7 @@ void drm_sysfs_lease_event(struct drm_device *dev);
 
 /* drm_gem.c */
 int drm_gem_init(struct drm_device *dev);
-bool drm_gem_object_handle_get_if_exists_unlocked(struct drm_gem_object *obj);
+void drm_gem_object_handle_get_unlocked(struct drm_gem_object *obj);
 void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj);
 int drm_gem_handle_create_tail(struct drm_file *file_priv,
 			       struct drm_gem_object *obj,
include/drm/drm_framebuffer.h +0 -7
index 38b24fc8978d..668077009fce 100644
@@ -23,7 +23,6 @@
 #ifndef __DRM_FRAMEBUFFER_H__
 #define __DRM_FRAMEBUFFER_H__
 
-#include <linux/bits.h>
 #include <linux/ctype.h>
 #include <linux/list.h>
 #include <linux/sched.h>
@@ -101,8 +100,6 @@ struct drm_framebuffer_funcs {
 		     unsigned num_clips);
 };
 
-#define DRM_FRAMEBUFFER_HAS_HANDLE_REF(_i)	BIT(0u + (_i))
-
 /**
  * struct drm_framebuffer - frame buffer object
  *
@@ -191,10 +188,6 @@ struct drm_framebuffer {
 	 * DRM_MODE_FB_MODIFIERS.
 	 */
 	int flags;
-	/**
-	 * @internal_flags: Framebuffer flags like DRM_FRAMEBUFFER_HAS_HANDLE_REF.
-	 */
-	unsigned int internal_flags;
 	/**
 	 * @filp_head: Placed on &drm_file.fbs, protected by &drm_file.fbs_lock.
 	 */
Signature · 1 line
2.47.2
#2 lore raw

PATCH 2/2 Revert "drm/gem: Acquire references on GEM handles for framebuffers"

In reply to Melissa Wen

This reverts commit 5307dce878d4126e1b375587318955bd019c3741.

We've already reverted all other commits related to dma_bug handling and there is still something wrong with this approach that does not allow unloading a driver. By reverting this commit, we'd just go back ot the old behavior.

---
 drivers/gpu/drm/drm_gem.c                    | 44 ++------------------
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 16 ++++---
 drivers/gpu/drm/drm_internal.h               |  2 -
 3 files changed, 11 insertions(+), 51 deletions(-)
drivers/gpu/drm/drm_gem.c +4 -40
index 09f80a84d61a..12efc04fb896 100644
@@ -213,35 +213,6 @@ void drm_gem_private_object_fini(struct drm_gem_object *obj)
 }
 EXPORT_SYMBOL(drm_gem_private_object_fini);
 
-static void drm_gem_object_handle_get(struct drm_gem_object *obj)
-{
-	struct drm_device *dev = obj->dev;
-
-	drm_WARN_ON(dev, !mutex_is_locked(&dev->object_name_lock));
-
-	if (obj->handle_count++ == 0)
-		drm_gem_object_get(obj);
-}
-
-/**
- * drm_gem_object_handle_get_unlocked - acquire reference on user-space handles
- * @obj: GEM object
- *
- * Acquires a reference on the GEM buffer object's handle. Required
- * to keep the GEM object alive. Call drm_gem_object_handle_put_unlocked()
- * to release the reference.
- */
-void drm_gem_object_handle_get_unlocked(struct drm_gem_object *obj)
-{
-	struct drm_device *dev = obj->dev;
-
-	guard(mutex)(&dev->object_name_lock);
-
-	drm_WARN_ON(dev, !obj->handle_count); /* first ref taken in create-tail helper */
-	drm_gem_object_handle_get(obj);
-}
-EXPORT_SYMBOL(drm_gem_object_handle_get_unlocked);
-
 /**
  * drm_gem_object_handle_free - release resources bound to userspace handles
  * @obj: GEM object to clean up.
@@ -272,14 +243,8 @@ static void drm_gem_object_exported_dma_buf_free(struct drm_gem_object *obj)
 	}
 }
 
-/**
- * drm_gem_object_handle_put_unlocked - releases reference on user-space handles
- * @obj: GEM object
- *
- * Releases a reference on the GEM buffer object's handle. Possibly releases
- * the GEM buffer object and associated dma-buf objects.
- */
-void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)
+static void
+drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)
 {
 	struct drm_device *dev = obj->dev;
 	bool final = false;
@@ -304,7 +269,6 @@ void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)
 	if (final)
 		drm_gem_object_put(obj);
 }
-EXPORT_SYMBOL(drm_gem_object_handle_put_unlocked);
 
 /*
  * Called at device or object close to release the file's
@@ -434,8 +398,8 @@ drm_gem_handle_create_tail(struct drm_file *file_priv,
 	int ret;
 
 	WARN_ON(!mutex_is_locked(&dev->object_name_lock));
-
-	drm_gem_object_handle_get(obj);
+	if (obj->handle_count++ == 0)
+		drm_gem_object_get(obj);
 
 	/*
 	 * Get the user-visible handle using idr.  Preload and perform
drivers/gpu/drm/drm_gem_framebuffer_helper.c +7 -9
index e364fa36ee36..4bc89d33df59 100644
@@ -101,7 +101,7 @@ void drm_gem_fb_destroy(struct drm_framebuffer *fb)
 	unsigned int i;
 
 	for (i = 0; i < fb->format->num_planes; i++)
-		drm_gem_object_handle_put_unlocked(fb->obj[i]);
+		drm_gem_object_put(fb->obj[i]);
 
 	drm_framebuffer_cleanup(fb);
 	kfree(fb);
@@ -179,10 +179,8 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
 		if (!objs[i]) {
 			drm_dbg_kms(dev, "Failed to lookup GEM object\n");
 			ret = -ENOENT;
-			goto err_gem_object_handle_put_unlocked;
+			goto err_gem_object_put;
 		}
-		drm_gem_object_handle_get_unlocked(objs[i]);
-		drm_gem_object_put(objs[i]);
 
 		min_size = (height - 1) * mode_cmd->pitches[i]
 			 + drm_format_info_min_pitch(info, i, width)
@@ -192,22 +190,22 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
 			drm_dbg_kms(dev,
 				    "GEM object size (%zu) smaller than minimum size (%u) for plane %d\n",
 				    objs[i]->size, min_size, i);
-			drm_gem_object_handle_put_unlocked(objs[i]);
+			drm_gem_object_put(objs[i]);
 			ret = -EINVAL;
-			goto err_gem_object_handle_put_unlocked;
+			goto err_gem_object_put;
 		}
 	}
 
 	ret = drm_gem_fb_init(dev, fb, info, mode_cmd, objs, i, funcs);
 	if (ret)
-		goto err_gem_object_handle_put_unlocked;
+		goto err_gem_object_put;
 
 	return 0;
 
-err_gem_object_handle_put_unlocked:
+err_gem_object_put:
 	while (i > 0) {
 		--i;
-		drm_gem_object_handle_put_unlocked(objs[i]);
+		drm_gem_object_put(objs[i]);
 	}
 	return ret;
 }
drivers/gpu/drm/drm_internal.h +0 -2
index ec1bf58e5714..5265eac81077 100644
@@ -163,8 +163,6 @@ void drm_sysfs_lease_event(struct drm_device *dev);
 
 /* drm_gem.c */
 int drm_gem_init(struct drm_device *dev);
-void drm_gem_object_handle_get_unlocked(struct drm_gem_object *obj);
-void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj);
 int drm_gem_handle_create_tail(struct drm_file *file_priv,
 			       struct drm_gem_object *obj,
 			       u32 *handlep);
Signature · 1 line
2.47.2
#3 lore raw

Re: [PATCH 2/2] Revert "drm/gem: Acquire references on GEM handles for framebuffers"

Quoted 6 lines · Melissa Wen

This reverts commit 5307dce878d4126e1b375587318955bd019c3741.

We've already reverted all other commits related to dma_bug handling and there is still something wrong with this approach that does not allow unloading a driver. By reverting this commit, we'd just go back ot the old behavior.

I don't think we want to do this.

Keeping the backing store alive for DMA-bufs while they are used for scanout is actually a really important bug fix.

Regards,
Christian.

Quoted 150 lines
---
 drivers/gpu/drm/drm_gem.c                    | 44 ++------------------
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 16 ++++---
 drivers/gpu/drm/drm_internal.h               |  2 -
 3 files changed, 11 insertions(+), 51 deletions(-)
drivers/gpu/drm/drm_gem.c +4 -40
index 09f80a84d61a..12efc04fb896 100644
@@ -213,35 +213,6 @@ void drm_gem_private_object_fini(struct drm_gem_object *obj)
 }
 EXPORT_SYMBOL(drm_gem_private_object_fini);
 
-static void drm_gem_object_handle_get(struct drm_gem_object *obj)
-{
-	struct drm_device *dev = obj->dev;
-
-	drm_WARN_ON(dev, !mutex_is_locked(&dev->object_name_lock));
-
-	if (obj->handle_count++ == 0)
-		drm_gem_object_get(obj);
-}
-
-/**
- * drm_gem_object_handle_get_unlocked - acquire reference on user-space handles
- * @obj: GEM object
- *
- * Acquires a reference on the GEM buffer object's handle. Required
- * to keep the GEM object alive. Call drm_gem_object_handle_put_unlocked()
- * to release the reference.
- */
-void drm_gem_object_handle_get_unlocked(struct drm_gem_object *obj)
-{
-	struct drm_device *dev = obj->dev;
-
-	guard(mutex)(&dev->object_name_lock);
-
-	drm_WARN_ON(dev, !obj->handle_count); /* first ref taken in create-tail helper */
-	drm_gem_object_handle_get(obj);
-}
-EXPORT_SYMBOL(drm_gem_object_handle_get_unlocked);
-
 /**
  * drm_gem_object_handle_free - release resources bound to userspace handles
  * @obj: GEM object to clean up.
@@ -272,14 +243,8 @@ static void drm_gem_object_exported_dma_buf_free(struct drm_gem_object *obj)
 	}
 }
 
-/**
- * drm_gem_object_handle_put_unlocked - releases reference on user-space handles
- * @obj: GEM object
- *
- * Releases a reference on the GEM buffer object's handle. Possibly releases
- * the GEM buffer object and associated dma-buf objects.
- */
-void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)
+static void
+drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)
 {
 	struct drm_device *dev = obj->dev;
 	bool final = false;
@@ -304,7 +269,6 @@ void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)
 	if (final)
 		drm_gem_object_put(obj);
 }
-EXPORT_SYMBOL(drm_gem_object_handle_put_unlocked);
 
 /*
  * Called at device or object close to release the file's
@@ -434,8 +398,8 @@ drm_gem_handle_create_tail(struct drm_file *file_priv,
 	int ret;
 
 	WARN_ON(!mutex_is_locked(&dev->object_name_lock));
-
-	drm_gem_object_handle_get(obj);
+	if (obj->handle_count++ == 0)
+		drm_gem_object_get(obj);
 
 	/*
 	 * Get the user-visible handle using idr.  Preload and perform
drivers/gpu/drm/drm_gem_framebuffer_helper.c +7 -9
index e364fa36ee36..4bc89d33df59 100644
@@ -101,7 +101,7 @@ void drm_gem_fb_destroy(struct drm_framebuffer *fb)
 	unsigned int i;
 
 	for (i = 0; i < fb->format->num_planes; i++)
-		drm_gem_object_handle_put_unlocked(fb->obj[i]);
+		drm_gem_object_put(fb->obj[i]);
 
 	drm_framebuffer_cleanup(fb);
 	kfree(fb);
@@ -179,10 +179,8 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
 		if (!objs[i]) {
 			drm_dbg_kms(dev, "Failed to lookup GEM object\n");
 			ret = -ENOENT;
-			goto err_gem_object_handle_put_unlocked;
+			goto err_gem_object_put;
 		}
-		drm_gem_object_handle_get_unlocked(objs[i]);
-		drm_gem_object_put(objs[i]);
 
 		min_size = (height - 1) * mode_cmd->pitches[i]
 			 + drm_format_info_min_pitch(info, i, width)
@@ -192,22 +190,22 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
 			drm_dbg_kms(dev,
 				    "GEM object size (%zu) smaller than minimum size (%u) for plane %d\n",
 				    objs[i]->size, min_size, i);
-			drm_gem_object_handle_put_unlocked(objs[i]);
+			drm_gem_object_put(objs[i]);
 			ret = -EINVAL;
-			goto err_gem_object_handle_put_unlocked;
+			goto err_gem_object_put;
 		}
 	}
 
 	ret = drm_gem_fb_init(dev, fb, info, mode_cmd, objs, i, funcs);
 	if (ret)
-		goto err_gem_object_handle_put_unlocked;
+		goto err_gem_object_put;
 
 	return 0;
 
-err_gem_object_handle_put_unlocked:
+err_gem_object_put:
 	while (i > 0) {
 		--i;
-		drm_gem_object_handle_put_unlocked(objs[i]);
+		drm_gem_object_put(objs[i]);
 	}
 	return ret;
 }
drivers/gpu/drm/drm_internal.h +0 -2
index ec1bf58e5714..5265eac81077 100644
@@ -163,8 +163,6 @@ void drm_sysfs_lease_event(struct drm_device *dev);
 
 /* drm_gem.c */
 int drm_gem_init(struct drm_device *dev);
-void drm_gem_object_handle_get_unlocked(struct drm_gem_object *obj);
-void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj);
 int drm_gem_handle_create_tail(struct drm_file *file_priv,
 			       struct drm_gem_object *obj,
 			       u32 *handlep);
#4 lore raw

Re: [PATCH 2/2] Revert "drm/gem: Acquire references on GEM handles for framebuffers"

Hi

Am 22.09.25 um 10:34 schrieb Christian König:

Quoted 10 lines · Melissa Wen
Quoted 6 lines

This reverts commit 5307dce878d4126e1b375587318955bd019c3741.

We've already reverted all other commits related to dma_bug handling and there is still something wrong with this approach that does not allow unloading a driver. By reverting this commit, we'd just go back ot the old behavior.

I don't think we want to do this.

Keeping the backing store alive for DMA-bufs while they are used for scanout is actually a really important bug fix.

That bug has rarely seen seen in practice. At least I'm not aware of any such report. And it's also just half of the fix IIRC. Not being able to unload the module is a regression OTOH. I'd rather go back to the old status quo than now having to deal with two problems.

Best regards
Thomas

Quoted 153 lines

Regards,
Christian.

Quoted 149 lines
---
  drivers/gpu/drm/drm_gem.c                    | 44 ++------------------
  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 16 ++++---
  drivers/gpu/drm/drm_internal.h               |  2 -
  3 files changed, 11 insertions(+), 51 deletions(-)
drivers/gpu/drm/drm_gem.c +4 -40
index 09f80a84d61a..12efc04fb896 100644
@@ -213,35 +213,6 @@ void drm_gem_private_object_fini(struct drm_gem_object *obj)
  }
  EXPORT_SYMBOL(drm_gem_private_object_fini);
 
-static void drm_gem_object_handle_get(struct drm_gem_object *obj)
-{
-	struct drm_device *dev = obj->dev;
-
-	drm_WARN_ON(dev, !mutex_is_locked(&dev->object_name_lock));
-
-	if (obj->handle_count++ == 0)
-		drm_gem_object_get(obj);
-}
-
-/**
- * drm_gem_object_handle_get_unlocked - acquire reference on user-space handles
- * @obj: GEM object
- *
- * Acquires a reference on the GEM buffer object's handle. Required
- * to keep the GEM object alive. Call drm_gem_object_handle_put_unlocked()
- * to release the reference.
- */
-void drm_gem_object_handle_get_unlocked(struct drm_gem_object *obj)
-{
-	struct drm_device *dev = obj->dev;
-
-	guard(mutex)(&dev->object_name_lock);
-
-	drm_WARN_ON(dev, !obj->handle_count); /* first ref taken in create-tail helper */
-	drm_gem_object_handle_get(obj);
-}
-EXPORT_SYMBOL(drm_gem_object_handle_get_unlocked);
-
  /**
   * drm_gem_object_handle_free - release resources bound to userspace handles
   * @obj: GEM object to clean up.
@@ -272,14 +243,8 @@ static void drm_gem_object_exported_dma_buf_free(struct drm_gem_object *obj)
  	}
  }
 
-/**
- * drm_gem_object_handle_put_unlocked - releases reference on user-space handles
- * @obj: GEM object
- *
- * Releases a reference on the GEM buffer object's handle. Possibly releases
- * the GEM buffer object and associated dma-buf objects.
- */
-void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)
+static void
+drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)
  {
  	struct drm_device *dev = obj->dev;
  	bool final = false;
@@ -304,7 +269,6 @@ void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)
  	if (final)
  		drm_gem_object_put(obj);
  }
-EXPORT_SYMBOL(drm_gem_object_handle_put_unlocked);
 
  /*
   * Called at device or object close to release the file's
@@ -434,8 +398,8 @@ drm_gem_handle_create_tail(struct drm_file *file_priv,
  	int ret;
 
  	WARN_ON(!mutex_is_locked(&dev->object_name_lock));
-
-	drm_gem_object_handle_get(obj);
+	if (obj->handle_count++ == 0)
+		drm_gem_object_get(obj);
 
  	/*
  	 * Get the user-visible handle using idr.  Preload and perform
drivers/gpu/drm/drm_gem_framebuffer_helper.c +7 -9
index e364fa36ee36..4bc89d33df59 100644
@@ -101,7 +101,7 @@ void drm_gem_fb_destroy(struct drm_framebuffer *fb)
  	unsigned int i;
 
  	for (i = 0; i < fb->format->num_planes; i++)
-		drm_gem_object_handle_put_unlocked(fb->obj[i]);
+		drm_gem_object_put(fb->obj[i]);
 
  	drm_framebuffer_cleanup(fb);
  	kfree(fb);
@@ -179,10 +179,8 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
  		if (!objs[i]) {
  			drm_dbg_kms(dev, "Failed to lookup GEM object\n");
  			ret = -ENOENT;
-			goto err_gem_object_handle_put_unlocked;
+			goto err_gem_object_put;
  		}
-		drm_gem_object_handle_get_unlocked(objs[i]);
-		drm_gem_object_put(objs[i]);
 
  		min_size = (height - 1) * mode_cmd->pitches[i]
  			 + drm_format_info_min_pitch(info, i, width)
@@ -192,22 +190,22 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
  			drm_dbg_kms(dev,
  				    "GEM object size (%zu) smaller than minimum size (%u) for plane %d\n",
  				    objs[i]->size, min_size, i);
-			drm_gem_object_handle_put_unlocked(objs[i]);
+			drm_gem_object_put(objs[i]);
  			ret = -EINVAL;
-			goto err_gem_object_handle_put_unlocked;
+			goto err_gem_object_put;
  		}
  	}
 
  	ret = drm_gem_fb_init(dev, fb, info, mode_cmd, objs, i, funcs);
  	if (ret)
-		goto err_gem_object_handle_put_unlocked;
+		goto err_gem_object_put;
 
  	return 0;
 
-err_gem_object_handle_put_unlocked:
+err_gem_object_put:
  	while (i > 0) {
  		--i;
-		drm_gem_object_handle_put_unlocked(objs[i]);
+		drm_gem_object_put(objs[i]);
  	}
  	return ret;
  }
drivers/gpu/drm/drm_internal.h +0 -2
index ec1bf58e5714..5265eac81077 100644
@@ -163,8 +163,6 @@ void drm_sysfs_lease_event(struct drm_device *dev);
 
  /* drm_gem.c */
  int drm_gem_init(struct drm_device *dev);
-void drm_gem_object_handle_get_unlocked(struct drm_gem_object *obj);
-void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj);
  int drm_gem_handle_create_tail(struct drm_file *file_priv,
  			       struct drm_gem_object *obj,
  			       u32 *handlep);
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#5 lore raw

Re: [PATCH 2/2] Revert "drm/gem: Acquire references on GEM handles for framebuffers"

Quoted 10 lines · Thomas Zimmermann

Hi

Am 22.09.25 um 10:34 schrieb Christian König:

Quoted 7 lines · Melissa Wen
Quoted 6 lines

This reverts commit 5307dce878d4126e1b375587318955bd019c3741.

We've already reverted all other commits related to dma_bug handling and there is still something wrong with this approach that does not allow unloading a driver. By reverting this commit, we'd just go back ot the old behavior.

Quoted 5 lines
Quoted 3 lines

I don't think we want to do this.

Keeping the backing store alive for DMA-bufs while they are used for scanout is actually a really important bug fix.

That bug has rarely seen seen in practice. At least I'm not aware of any such report. And it's also just half of the fix IIRC. Not being able to unload the module is a regression OTOH. I'd rather go back to the old status quo than now having to deal with two problems.

Yeah wait a second, not being able to unload the module is potentially the right thing to do.

So were is that module reference actually coming from? And why do we have it now and didn't had it previously?

Regards,
Christian.

Quoted 146 lines

Best regards
Thomas

Quoted 141 lines

Regards,
Christian.

Quoted 137 lines

---
  drivers/gpu/drm/drm_gem.c                    | 44 ++------------------ drivers/gpu/drm/drm_gem_framebuffer_helper.c | 16 ++++--- drivers/gpu/drm/drm_internal.h               |  2 -

  3 files changed, 11 insertions(+), 51 deletions(-)
drivers/gpu/drm/drm_gem.c +0 -28
index 09f80a84d61a..12efc04fb896 100644
@@ -213,35 +213,6 @@ void drm_gem_private_object_fini(struct drm_gem_object *obj)
   }
   EXPORT_SYMBOL(drm_gem_private_object_fini);
   -static void drm_gem_object_handle_get(struct drm_gem_object *obj)
-{
-    struct drm_device *dev = obj->dev;
-
-    drm_WARN_ON(dev, !mutex_is_locked(&dev->object_name_lock));
-
-    if (obj->handle_count++ == 0)
-        drm_gem_object_get(obj);
-}
-
-/**
- * drm_gem_object_handle_get_unlocked - acquire reference on user-space handles
- * @obj: GEM object
- *
- * Acquires a reference on the GEM buffer object's handle. Required
- * to keep the GEM object alive. Call drm_gem_object_handle_put_unlocked()
- * to release the reference.
- */
-void drm_gem_object_handle_get_unlocked(struct drm_gem_object *obj)
-{
-    struct drm_device *dev = obj->dev;
-
-    guard(mutex)(&dev->object_name_lock);
-
-    drm_WARN_ON(dev, !obj->handle_count); /* first ref taken in create-tail helper */
-    drm_gem_object_handle_get(obj);
-}
-EXPORT_SYMBOL(drm_gem_object_handle_get_unlocked);
-
   /**
    * drm_gem_object_handle_free - release resources bound to userspace handles
    * @obj: GEM object to clean up.
@@ -272,14 +243,8 @@ static void drm_gem_object_exported_dma_buf_free(struct drm_gem_object *obj)
       }
   }

  -/**
- * drm_gem_object_handle_put_unlocked - releases reference on user-space handles
- * @obj: GEM object
- *
- * Releases a reference on the GEM buffer object's handle. Possibly releases
- * the GEM buffer object and associated dma-buf objects.
- */

drivers/gpu/drm/drm_gem.c +2 -1
-void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)
+static void
+drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)

  {
      struct drm_device *dev = obj->dev;
      bool final = false;

drivers/gpu/drm/drm_gem.c +2 -3
@@ -304,7 +269,6 @@ void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj)
       if (final)
           drm_gem_object_put(obj);
   }
-EXPORT_SYMBOL(drm_gem_object_handle_put_unlocked);
     /*
    * Called at device or object close to release the file's
@@ -434,8 +398,8 @@ drm_gem_handle_create_tail(struct drm_file *file_priv,
       int ret;
         WARN_ON(!mutex_is_locked(&dev->object_name_lock));
-
-    drm_gem_object_handle_get(obj);
+    if (obj->handle_count++ == 0)
+        drm_gem_object_get(obj);
         /*
        * Get the user-visible handle using idr.  Preload and perform
drivers/gpu/drm/drm_gem_framebuffer_helper.c +2 -4
index e364fa36ee36..4bc89d33df59 100644
@@ -101,7 +101,7 @@ void drm_gem_fb_destroy(struct drm_framebuffer *fb)
       unsigned int i;
         for (i = 0; i < fb->format->num_planes; i++)
-        drm_gem_object_handle_put_unlocked(fb->obj[i]);
+        drm_gem_object_put(fb->obj[i]);
         drm_framebuffer_cleanup(fb);
       kfree(fb);
@@ -179,10 +179,8 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
           if (!objs[i]) {
               drm_dbg_kms(dev, "Failed to lookup GEM object\n");
               ret = -ENOENT;
-            goto err_gem_object_handle_put_unlocked;
+            goto err_gem_object_put;
           }
-        drm_gem_object_handle_get_unlocked(objs[i]);
-        drm_gem_object_put(objs[i]);

            min_size = (height - 1) * mode_cmd->pitches[i]
               + drm_format_info_min_pitch(info, i, width)

drivers/gpu/drm/drm_gem_framebuffer_helper.c +3 -3
@@ -192,22 +190,22 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
               drm_dbg_kms(dev,
                       "GEM object size (%zu) smaller than minimum size (%u) for plane %d\n",
                       objs[i]->size, min_size, i);
-            drm_gem_object_handle_put_unlocked(objs[i]);
+            drm_gem_object_put(objs[i]);
               ret = -EINVAL;
-            goto err_gem_object_handle_put_unlocked;
+            goto err_gem_object_put;
           }
       }
         ret = drm_gem_fb_init(dev, fb, info, mode_cmd, objs, i, funcs);
       if (ret)
-        goto err_gem_object_handle_put_unlocked;
+        goto err_gem_object_put;
         return 0;

  -err_gem_object_handle_put_unlocked:
+err_gem_object_put:
      while (i > 0) {
          --i;
-        drm_gem_object_handle_put_unlocked(objs[i]); +        drm_gem_object_put(objs[i]);
      }
      return ret;
  }

drivers/gpu/drm/drm_internal.h +0 -2
index ec1bf58e5714..5265eac81077 100644
@@ -163,8 +163,6 @@ void drm_sysfs_lease_event(struct drm_device *dev);
     /* drm_gem.c */
   int drm_gem_init(struct drm_device *dev);
-void drm_gem_object_handle_get_unlocked(struct drm_gem_object *obj);
-void drm_gem_object_handle_put_unlocked(struct drm_gem_object *obj);
   int drm_gem_handle_create_tail(struct drm_file *file_priv,
                      struct drm_gem_object *obj,
                      u32 *handlep);
#6 lore raw

Re: [PATCH 2/2] Revert "drm/gem: Acquire references on GEM handles for framebuffers"

In reply to Melissa Wen

Hey,

Quoted 6 lines · Melissa Wen

This reverts commit 5307dce878d4126e1b375587318955bd019c3741.

We've already reverted all other commits related to dma_bug handling and there is still something wrong with this approach that does not allow unloading a driver. By reverting this commit, we'd just go back ot the old behavior.

This is actually important to keep. i915 and xe already do this for similar reasons, so I'm glad it's enforced across all drivers. Without this you can do this:
- CreateFB
- destroy gem object
- Have random memory being scanout.

I'd rather keep it. If amd no longer unloads, figure out why. I know there are igt tests for module load, do those work?

Best regards,
~Maarten

maintainer Acked-by on the v1 series
#7 lore raw
In reply to Melissa Wen

Hi

Am 19.09.25 um 17:54 schrieb Melissa Wen:

Quoted 5 lines

Hi all,

I just talked with Thomas that these two patches are preventing amdgpu driver to be unloaded:

Quoted 8 lines

modprobe: FATAL: Module amdgpu is in use.

and there is no process using the driver.

We agreed that the best approach now is to completely revert the work done for improving DMA bug handling to avoid any loose ends. With these reverts we are just back to the old behavior and amdgpu loading and unloading will return to normal.

For both patches

If no complains come in, I'll send them out with this week's drm-misc-next-fixes.

Best regards
Thomas

Quoted 15 lines

Best Regards,

Melissa

Melissa Wen (2):
Revert "drm/framebuffer: Acquire internal references on GEM handles" Revert "drm/gem: Acquire references on GEM handles for framebuffers"

  drivers/gpu/drm/drm_framebuffer.c | 31 +--------------
  drivers/gpu/drm/drm_gem.c         | 64 +++++--------------------------
  drivers/gpu/drm/drm_internal.h    |  2 -
  include/drm/drm_framebuffer.h     |  7 ----
  4 files changed, 11 insertions(+), 93 deletions(-)
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#8 lore raw
In reply to Melissa Wen

Hi Melissa

Am 19.09.25 um 17:54 schrieb Melissa Wen:

Quoted 8 lines

Hi all,

I just talked with Thomas that these two patches are preventing amdgpu driver to be unloaded:

modprobe: FATAL: Module amdgpu is in use.

and there is no process using the driver.

What's the exact STR for this problem? After Christian's comments, I tried to reproduce the issue, but it works on my system. I do

- boot up with amdgpu in text mode (multiuser.target)
- login by serial console
- 'rmmod amdgpu'

That last step turns my test system's display off and unloads amdgpu. The kernel is a recent drm-tip at v6.17-rc6.

Best regards
Thomas

Quoted 20 lines

We agreed that the best approach now is to completely revert the work done for improving DMA bug handling to avoid any loose ends. With these reverts we are just back to the old behavior and amdgpu loading and unloading will return to normal.

Best Regards,

Melissa

Melissa Wen (2):
Revert "drm/framebuffer: Acquire internal references on GEM handles" Revert "drm/gem: Acquire references on GEM handles for framebuffers"

  drivers/gpu/drm/drm_framebuffer.c | 31 +--------------
  drivers/gpu/drm/drm_gem.c         | 64 +++++--------------------------
  drivers/gpu/drm/drm_internal.h    |  2 -
  include/drm/drm_framebuffer.h     |  7 ----
  4 files changed, 11 insertions(+), 93 deletions(-)
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#9 lore raw
Quoted 11 lines · Thomas Zimmermann

Hi Melissa

Am 19.09.25 um 17:54 schrieb Melissa Wen:

Quoted 8 lines

Hi all,

I just talked with Thomas that these two patches are preventing amdgpu driver to be unloaded:

modprobe: FATAL: Module amdgpu is in use.

and there is no process using the driver.

Melissa could it be that you have a console loaded?

Regards,
Christian.

Quoted 33 lines

What's the exact STR for this problem? After Christian's comments, I tried to reproduce the issue, but it works on my system. I do

- boot up with amdgpu in text mode (multiuser.target)
- login by serial console
- 'rmmod amdgpu'

That last step turns my test system's display off and unloads amdgpu. The kernel is a recent drm-tip at v6.17-rc6.

Best regards
Thomas

Quoted 20 lines

We agreed that the best approach now is to completely revert the work done for improving DMA bug handling to avoid any loose ends. With these reverts we are just back to the old behavior and amdgpu loading and unloading will return to normal.

Best Regards,

Melissa

Melissa Wen (2):
   Revert "drm/framebuffer: Acquire internal references on GEM handles" Revert "drm/gem: Acquire references on GEM handles for framebuffers"

  drivers/gpu/drm/drm_framebuffer.c | 31 +-------------- drivers/gpu/drm/drm_gem.c         | 64 +++++-------------------------- drivers/gpu/drm/drm_internal.h    |  2 - include/drm/drm_framebuffer.h     |  7 ----

  4 files changed, 11 insertions(+), 93 deletions(-)
#10 lore raw

Am 22.09.25 um 13:55 schrieb Christian König:

Quoted 6 lines · Thomas Zimmermann
Quoted 5 lines

Hi Melissa

Am 19.09.25 um 17:54 schrieb Melissa Wen:

Quoted 2 lines

Hi all,

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

I just talked with Thomas that these two patches are preventing amdgpu driver to be unloaded:

modprobe: FATAL: Module amdgpu is in use.

and there is no process using the driver.

Melissa could it be that you have a console loaded?

FTR I can also do 'rmmod amdgpu' from amdgpu's fbcon successfully.

Quoted 34 lines

Regards,
Christian.

Quoted 30 lines

What's the exact STR for this problem? After Christian's comments, I tried to reproduce the issue, but it works on my system. I do

- boot up with amdgpu in text mode (multiuser.target)
- login by serial console
- 'rmmod amdgpu'

That last step turns my test system's display off and unloads amdgpu. The kernel is a recent drm-tip at v6.17-rc6.

Best regards
Thomas

Quoted 19 lines

We agreed that the best approach now is to completely revert the work done for improving DMA bug handling to avoid any loose ends. With these reverts we are just back to the old behavior and amdgpu loading and unloading will return to normal.

Best Regards,

Melissa

Melissa Wen (2):
   Revert "drm/framebuffer: Acquire internal references on GEM handles" Revert "drm/gem: Acquire references on GEM handles for framebuffers"

   drivers/gpu/drm/drm_framebuffer.c | 31 +--------------
   drivers/gpu/drm/drm_gem.c         | 64 +++++--------------------------
   drivers/gpu/drm/drm_internal.h    |  2 -
   include/drm/drm_framebuffer.h     |  7 ----
   4 files changed, 11 insertions(+), 93 deletions(-)
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#11 lore raw
In reply to Thomas Zimmermann
Quoted 12 lines · Thomas Zimmermann

Hi Melissa

Am 19.09.25 um 17:54 schrieb Melissa Wen:

Quoted 8 lines

Hi all,

I just talked with Thomas that these two patches are preventing amdgpu driver to be unloaded:

modprobe: FATAL: Module amdgpu is in use.

and there is no process using the driver.

Quoted 7 lines

What's the exact STR for this problem? After Christian's comments, I tried to reproduce the issue, but it works on my system. I do

- boot up with amdgpu in text mode (multiuser.target)
- login by serial console
- 'rmmod amdgpu'

That last step turns my test system's display off and unloads amdgpu. The kernel is a recent drm-tip at v6.17-rc6.

- I booted up in graphical.target;
- Connected via ssh, dropped the graphical interface to text mode (multiuser.target), and tried to remove the module with modprobe -r amdgpu

The issue happened in the latest 6.16 kernel version from Debian (I don't have the machine with me atm to check the exact version), but also with mainline kernel from last week.

I bisected kernel from 6.16 and 6.15 and IIRC git bisect pointed to drm/framebuffer: Acquire internal references on GEM handles, but as it triggers another trace and AFAIU fixes drm/gem: Acquire references on GEM handles for framebuffers, I reverted both pacthes and amdgpu loaded/unloaded as expected.

IGT amdgpu-specific tests for loading and unloading are also failing because it's not able to unload the module. I didn't run the generic test.

I'm using an AMD Cezanne laptop with a touch-screen capable display (hp envy x360 convertible) with Debian + Gnome. I looked for process using the modules, but I didn't find any.

BTW, I don't discard that this work uncovered a preexist problem, for example.
Since those patches are addressing other issues, as mentioned by Maarten, I'll debug the amdgpu driver further and check the points raised.

Best Regards,

Melissa

Quoted 25 lines

Best regards
Thomas

Quoted 20 lines

We agreed that the best approach now is to completely revert the work done for improving DMA bug handling to avoid any loose ends. With these reverts we are just back to the old behavior and amdgpu loading and unloading will return to normal.

Best Regards,

Melissa

Melissa Wen (2):
   Revert "drm/framebuffer: Acquire internal references on GEM handles" Revert "drm/gem: Acquire references on GEM handles for framebuffers"

  drivers/gpu/drm/drm_framebuffer.c | 31 +-------------- drivers/gpu/drm/drm_gem.c         | 64 +++++-------------------------- drivers/gpu/drm/drm_internal.h    |  2 - include/drm/drm_framebuffer.h     |  7 ----

  4 files changed, 11 insertions(+), 93 deletions(-)
#12 lore raw
Quoted 28 lines · Melissa Wen
Quoted 12 lines · Thomas Zimmermann

Hi Melissa

Am 19.09.25 um 17:54 schrieb Melissa Wen:

Quoted 8 lines

Hi all,

I just talked with Thomas that these two patches are preventing amdgpu driver to be unloaded:

modprobe: FATAL: Module amdgpu is in use.

and there is no process using the driver.

Quoted 7 lines

What's the exact STR for this problem? After Christian's comments, I tried to reproduce the issue, but it works on my system. I do

- boot up with amdgpu in text mode (multiuser.target)
- login by serial console
- 'rmmod amdgpu'

That last step turns my test system's display off and unloads amdgpu. The kernel is a recent drm-tip at v6.17-rc6.

- I booted up in graphical.target;
- Connected via ssh, dropped the graphical interface to text mode (multiuser.target), and tried to remove the module with modprobe -r amdgpu

The issue happened in the latest 6.16 kernel version from Debian (I don't have the machine with me atm to check the exact version), but also with mainline kernel from last week.

I bisected kernel from 6.16 and 6.15 and IIRC git bisect pointed to drm/framebuffer: Acquire internal references on GEM handles, but as it triggers another trace and AFAIU fixes drm/gem: Acquire references on GEM handles for framebuffers, I reverted both pacthes and amdgpu loaded/unloaded as expected.

Quoted 8 lines

IGT amdgpu-specific tests for loading and unloading are also failing because it's not able to unload the module. I didn't run the generic test.

I'm using an AMD Cezanne laptop with a touch-screen capable display (hp envy x360 convertible) with Debian + Gnome. I looked for process using the modules, but I didn't find any.

BTW, I don't discard that this work uncovered a preexist problem, for example.
Since those patches are addressing other issues, as mentioned by Maarten, I'll debug the amdgpu driver further and check the points raised.

Well could it be that the graphics target left a CRTC running and a framebuffer being scanned out?

Regards,
Christian.

Quoted 31 lines

Best Regards,

Melissa

Quoted 25 lines

Best regards
Thomas

Quoted 20 lines

We agreed that the best approach now is to completely revert the work done for improving DMA bug handling to avoid any loose ends. With these reverts we are just back to the old behavior and amdgpu loading and unloading will return to normal.

Best Regards,

Melissa

Melissa Wen (2):
   Revert "drm/framebuffer: Acquire internal references on GEM handles" Revert "drm/gem: Acquire references on GEM handles for framebuffers"

  drivers/gpu/drm/drm_framebuffer.c | 31 +-------------- drivers/gpu/drm/drm_gem.c         | 64 +++++-------------------------- drivers/gpu/drm/drm_internal.h    |  2 - include/drm/drm_framebuffer.h     |  7 ----

  4 files changed, 11 insertions(+), 93 deletions(-)
#13 lore raw
In reply to Melissa Wen

Hi

Am 22.09.25 um 15:42 schrieb Melissa Wen:

Quoted 21 lines · Thomas Zimmermann
Quoted 18 lines

Hi Melissa

Am 19.09.25 um 17:54 schrieb Melissa Wen:

Quoted 8 lines

Hi all,

I just talked with Thomas that these two patches are preventing amdgpu driver to be unloaded:

modprobe: FATAL: Module amdgpu is in use.

and there is no process using the driver.

What's the exact STR for this problem? After Christian's comments, I tried to reproduce the issue, but it works on my system. I do

- boot up with amdgpu in text mode (multiuser.target)
- login by serial console
- 'rmmod amdgpu'

Quoted 5 lines
Quoted 1 line

That last step turns my test system's display off and unloads amdgpu. The kernel is a recent drm-tip at v6.17-rc6.

- I booted up in graphical.target;
- Connected via ssh, dropped the graphical interface to text mode (multiuser.target), and tried to remove the module with modprobe -r amdgpu

I do

- boot into graphical
- ssh into the test system
- via ssh: sudo systemctl isolate multi-user.target
- via ssh: sudo modprobe -r amdgpu

Works as expected.

Quoted 10 lines

The issue happened in the latest 6.16 kernel version from Debian (I don't have the machine with me atm to check the exact version), but also with mainline kernel from last week.

I bisected kernel from 6.16 and 6.15 and IIRC git bisect pointed to drm/framebuffer: Acquire internal references on GEM handles, but as it triggers another trace and AFAIU fixes drm/gem: Acquire references on GEM handles for framebuffers, I reverted both pacthes and amdgpu loaded/unloaded as expected.

IGT amdgpu-specific tests for loading and unloading are also failing because it's not able to unload the module. I didn't run the generic test.

I'm using an AMD Cezanne laptop with a touch-screen capable display (hp envy x360 convertible) with Debian + Gnome. I looked for process using the modules, but I didn't find any.

After you switched to multi-user, what is in /sys/kernel/debug/dri/<YOUR DRM DEV>/ framebuffer ?

There should only be a single fb allocated by fbcon.

Quoted 3 lines

BTW, I don't discard that this work uncovered a preexist problem, for example.
Since those patches are addressing other issues, as mentioned by Maarten, I'll debug the amdgpu driver further and check the points raised.

Thanks

Best regards
Thomas

Quoted 32 lines

Best Regards,

Melissa

Quoted 26 lines

Best regards
Thomas

Quoted 21 lines

We agreed that the best approach now is to completely revert the work done for improving DMA bug handling to avoid any loose ends. With these reverts we are just back to the old behavior and amdgpu loading and unloading will return to normal.

Best Regards,

Melissa

Melissa Wen (2):
   Revert "drm/framebuffer: Acquire internal references on GEM handles" Revert "drm/gem: Acquire references on GEM handles for framebuffers"

  drivers/gpu/drm/drm_framebuffer.c | 31 +-------------- drivers/gpu/drm/drm_gem.c         | 64
+++++--------------------------
  drivers/gpu/drm/drm_internal.h    |  2 - include/drm/drm_framebuffer.h     |  7 ----

  4 files changed, 11 insertions(+), 93 deletions(-)
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)