diff mbox

[RFC,v4,20/25] drm/prime: Don't pin module on export for in-kernel clients

Message ID 20180412161237.9314-9-noralf@tronnes.org (mailing list archive)
State New, archived
Headers show

Commit Message

Noralf Trønnes April 12, 2018, 4:12 p.m. UTC
Avoid pinning the module when exporting a GEM object as a dmabuf. This
makes it possible to unload drivers that has in-kernel clients using it.
The client is removed on drm_dev_unregister() so no need to pin the driver.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
---
 drivers/gpu/drm/drm_prime.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index e6052ab2bec4..f9dbe3b9db20 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -567,6 +567,30 @@  struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
 		.flags = flags,
 		.priv = obj,
 	};
+	bool is_internal = false;
+	struct drm_file *file;
+
+	mutex_lock(&dev->filelist_mutex);
+	list_for_each_entry(file, &dev->filelist_internal, lhead) {
+		struct drm_gem_object *iter;
+		int id;
+
+		spin_lock(&file->table_lock);
+		idr_for_each_entry(&file->object_idr, iter, id) {
+			if (iter == obj) {
+				is_internal = true;
+				break;
+			}
+		}
+		spin_unlock(&file->table_lock);
+
+		if (is_internal)
+			break;
+	}
+	mutex_unlock(&dev->filelist_mutex);
+
+	if (is_internal)
+		exp_info.owner = NULL;
 
 	if (dev->driver->gem_prime_res_obj)
 		exp_info.resv = dev->driver->gem_prime_res_obj(obj);