Skip to contentSkip to conversation

drm/qxl: driver release fixes.

PATCH In review Gerd Hoffmann 3 participants 6 messages Feb 10, 2020

Subsystems (4)
lore
Share & tools
lore

Gerd Hoffmann

author maintainer
#0 lore raw

v2 cover drm/qxl: driver release fixes.

Gerd Hoffmann (2):
drm/qxl: reorder calls in qxl_device_fini().
drm/qxl: add drm_driver.release callback.

 drivers/gpu/drm/qxl/qxl_drv.c | 26 +++++++++++++++++++-------
 drivers/gpu/drm/qxl/qxl_kms.c |  8 ++++----
 2 files changed, 23 insertions(+), 11 deletions(-)
Signature · 6 lines
2.18.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#1 lore raw

PATCH v2 1/2 drm/qxl: reorder calls in qxl_device_fini().

Reorder calls in qxl_device_fini(). Cleaning up gem & ttm might trigger qxl commands, so we should do that before releaseing command rings.

---
 drivers/gpu/drm/qxl/qxl_kms.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/qxl/qxl_kms.c +4 -4
index bfc1631093e9..70b20ee4741a 100644
@@ -299,12 +299,12 @@ void qxl_device_fini(struct qxl_device *qdev)
 {
 	qxl_bo_unref(&qdev->current_release_bo[0]);
 	qxl_bo_unref(&qdev->current_release_bo[1]);
-	flush_work(&qdev->gc_work);
-	qxl_ring_free(qdev->command_ring);
-	qxl_ring_free(qdev->cursor_ring);
-	qxl_ring_free(qdev->release_ring);
 	qxl_gem_fini(qdev);
 	qxl_bo_fini(qdev);
+	flush_work(&qdev->gc_work);
+	qxl_ring_free(qdev->command_ring);
+	qxl_ring_free(qdev->cursor_ring);
+	qxl_ring_free(qdev->release_ring);
 	io_mapping_free(qdev->surface_mapping);
 	io_mapping_free(qdev->vram_mapping);
 	iounmap(qdev->ram_header);
Signature · 1 line
2.18.1
author maintainer
#2 lore raw

PATCH v2 2/2 drm/qxl: add drm_driver.release callback.

In reply to Gerd Hoffmann

Move final cleanups to qxl_drm_release() callback. Add drm_atomic_helper_shutdown() call to qxl_pci_remove().

---
 drivers/gpu/drm/qxl/qxl_drv.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/gpu/drm/qxl/qxl_drv.c +19 -7
index 1d601f57a6ba..4fda3f9b29f4 100644
@@ -34,6 +34,7 @@
 #include <linux/pci.h>
 
 #include <drm/drm.h>
+#include <drm/drm_atomic_helper.h>
 #include <drm/drm_drv.h>
 #include <drm/drm_file.h>
 #include <drm/drm_modeset_helper.h>
@@ -132,21 +133,30 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	return ret;
 }
 
+static void qxl_drm_release(struct drm_device *dev)
+{
+	struct qxl_device *qdev = dev->dev_private;
+
+	/*
+	 * TODO: qxl_device_fini() call should be in qxl_pci_remove(),
+	 * reodering qxl_modeset_fini() + qxl_device_fini() calls is
+	 * non-trivial though.
+	 */
+	qxl_modeset_fini(qdev);
+	qxl_device_fini(qdev);
+	dev->dev_private = NULL;
+	kfree(qdev);
+}
+
 static void
 qxl_pci_remove(struct pci_dev *pdev)
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
-	struct qxl_device *qdev = dev->dev_private;
 
 	drm_dev_unregister(dev);
-
-	qxl_modeset_fini(qdev);
-	qxl_device_fini(qdev);
+	drm_atomic_helper_shutdown(dev);
 	if (is_vga(pdev))
 		vga_put(pdev, VGA_RSRC_LEGACY_IO);
-
-	dev->dev_private = NULL;
-	kfree(qdev);
 	drm_dev_put(dev);
 }
 
@@ -279,6 +289,8 @@ static struct drm_driver qxl_driver = {
 	.major = 0,
 	.minor = 1,
 	.patchlevel = 0,
+
+	.release = qxl_drm_release,
 };
 
 static int __init qxl_init(void)
Signature · 1 line
2.18.1
Acked-by on v2 2/2
#3 lore raw

Re: [PATCH v2 2/2] drm/qxl: add drm_driver.release callback.

Quoted 24 lines · Gerd Hoffmann

Move final cleanups to qxl_drm_release() callback. Add drm_atomic_helper_shutdown() call to qxl_pci_remove().

---
 drivers/gpu/drm/qxl/qxl_drv.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/gpu/drm/qxl/qxl_drv.c +1 -0
index 1d601f57a6ba..4fda3f9b29f4 100644
@@ -34,6 +34,7 @@
 #include <linux/pci.h>
 
 #include <drm/drm.h>
+#include <drm/drm_atomic_helper.h>
 #include <drm/drm_drv.h>
 #include <drm/drm_file.h>
 #include <drm/drm_modeset_helper.h>
@@ -132,21 +133,30 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	return ret;
 }
 

drivers/gpu/drm/qxl/qxl_drv.c qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 145

Quoted 10 lines
drivers/gpu/drm/qxl/qxl_drv.c +10 -0
+static void qxl_drm_release(struct drm_device *dev)
+{
+	struct qxl_device *qdev = dev->dev_private;
+
+	/*
+	 * TODO: qxl_device_fini() call should be in qxl_pci_remove(),
+	 * reodering qxl_modeset_fini() + qxl_device_fini() calls is
+	 * non-trivial though.
+	 */
+	qxl_modeset_fini(qdev);

So the drm_mode_config_cleanup call in here belongs in ->release, but the qxl_destroy_monitors_object feels like should be perfectly fine in the remove hook. You might need to sprinkle a few drm_dev_enter/exit around to protect code paths thought.

Aside from this lgtm, for the series

And up to you whether you want to fix this or not really.

Btw for testing all these patches that add a ->release hook I think it'd be good if the drm core checks that drm_device->dev is set to NULL, and that we do this in the remove hook. Since that's guaranteed to be gone at that point, so anything in ->release that still needs the device is broken. Ofc maybe do that check only for drivers which have a ->release hook, and we might need a few fixups.

Cheers, Daniel

Quoted 36 lines
drivers/gpu/drm/qxl/qxl_drv.c +8 -7
+	qxl_device_fini(qdev);
+	dev->dev_private = NULL;
+	kfree(qdev);
+}
+
 static void
 qxl_pci_remove(struct pci_dev *pdev)
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
-	struct qxl_device *qdev = dev->dev_private;
 
 	drm_dev_unregister(dev);
-
-	qxl_modeset_fini(qdev);
-	qxl_device_fini(qdev);
+	drm_atomic_helper_shutdown(dev);
 	if (is_vga(pdev))
 		vga_put(pdev, VGA_RSRC_LEGACY_IO);
-
-	dev->dev_private = NULL;
-	kfree(qdev);
 	drm_dev_put(dev);
 }
 
@@ -279,6 +289,8 @@ static struct drm_driver qxl_driver = {
 	.major = 0,
 	.minor = 1,
 	.patchlevel = 0,
+
+	.release = qxl_drm_release,
 };
 
 static int __init qxl_init(void)
Signature · 1 line
2.18.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#4 lore raw

Re: [PATCH v2 2/2] drm/qxl: add drm_driver.release callback.

Den 10.02.2020 16.06, skrev Daniel Vetter:

Quoted 45 lines · Gerd Hoffmann
Quoted 24 lines

Move final cleanups to qxl_drm_release() callback. Add drm_atomic_helper_shutdown() call to qxl_pci_remove().

---
 drivers/gpu/drm/qxl/qxl_drv.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/gpu/drm/qxl/qxl_drv.c +1 -0
index 1d601f57a6ba..4fda3f9b29f4 100644
@@ -34,6 +34,7 @@
 #include <linux/pci.h>
 
 #include <drm/drm.h>
+#include <drm/drm_atomic_helper.h>
 #include <drm/drm_drv.h>
 #include <drm/drm_file.h>
 #include <drm/drm_modeset_helper.h>
@@ -132,21 +133,30 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	return ret;
 }
 

drivers/gpu/drm/qxl/qxl_drv.c qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 145

Quoted 10 lines
drivers/gpu/drm/qxl/qxl_drv.c +10 -0
+static void qxl_drm_release(struct drm_device *dev)
+{
+	struct qxl_device *qdev = dev->dev_private;
+
+	/*
+	 * TODO: qxl_device_fini() call should be in qxl_pci_remove(),
+	 * reodering qxl_modeset_fini() + qxl_device_fini() calls is
+	 * non-trivial though.
+	 */
+	qxl_modeset_fini(qdev);

So the drm_mode_config_cleanup call in here belongs in ->release, but the qxl_destroy_monitors_object feels like should be perfectly fine in the remove hook. You might need to sprinkle a few drm_dev_enter/exit around to protect code paths thought.

Aside from this lgtm, for the series

Quoted 9 lines

And up to you whether you want to fix this or not really.

Btw for testing all these patches that add a ->release hook I think it'd be good if the drm core checks that drm_device->dev is set to NULL, and that we do this in the remove hook. Since that's guaranteed to be gone at that point, so anything in ->release that still needs the device is broken. Ofc maybe do that check only for drivers which have a ->release hook, and we might need a few fixups.

We take a ref on the parent device in drm_dev_init() and release it in drm_dev_fini(). I added this because of the DRM_DEV_* macros we have, to protect access to the device struct after it was unregistered. Setting drm_device->dev to NULL in drm_dev_unregister() instead will provide the same protection I think.

commit 56be6503aab2
drm/drv: Hold ref on parent device during drm_device lifetime

Noralf.

Quoted 39 lines

Cheers, Daniel

Quoted 36 lines
drivers/gpu/drm/qxl/qxl_drv.c +8 -7
+	qxl_device_fini(qdev);
+	dev->dev_private = NULL;
+	kfree(qdev);
+}
+
 static void
 qxl_pci_remove(struct pci_dev *pdev)
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
-	struct qxl_device *qdev = dev->dev_private;
 
 	drm_dev_unregister(dev);
-
-	qxl_modeset_fini(qdev);
-	qxl_device_fini(qdev);
+	drm_atomic_helper_shutdown(dev);
 	if (is_vga(pdev))
 		vga_put(pdev, VGA_RSRC_LEGACY_IO);
-
-	dev->dev_private = NULL;
-	kfree(qdev);
 	drm_dev_put(dev);
 }
 
@@ -279,6 +289,8 @@ static struct drm_driver qxl_driver = {
 	.major = 0,
 	.minor = 1,
 	.patchlevel = 0,
+
+	.release = qxl_drm_release,
 };
 
 static int __init qxl_init(void)
Signature · 1 line
2.18.1
#5 lore raw

Re: [PATCH v2 2/2] drm/qxl: add drm_driver.release callback.

(adding back Daniel)

Den 10.02.2020 17.57, skrev Noralf Trønnes:

Quoted 113 lines

Den 10.02.2020 16.06, skrev Daniel Vetter:

Quoted 45 lines · Gerd Hoffmann
Quoted 24 lines

Move final cleanups to qxl_drm_release() callback. Add drm_atomic_helper_shutdown() call to qxl_pci_remove().

---
 drivers/gpu/drm/qxl/qxl_drv.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/gpu/drm/qxl/qxl_drv.c +1 -0
index 1d601f57a6ba..4fda3f9b29f4 100644
@@ -34,6 +34,7 @@
 #include <linux/pci.h>
 
 #include <drm/drm.h>
+#include <drm/drm_atomic_helper.h>
 #include <drm/drm_drv.h>
 #include <drm/drm_file.h>
 #include <drm/drm_modeset_helper.h>
@@ -132,21 +133,30 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	return ret;
 }
 

drivers/gpu/drm/qxl/qxl_drv.c qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 145

Quoted 10 lines
drivers/gpu/drm/qxl/qxl_drv.c +10 -0
+static void qxl_drm_release(struct drm_device *dev)
+{
+	struct qxl_device *qdev = dev->dev_private;
+
+	/*
+	 * TODO: qxl_device_fini() call should be in qxl_pci_remove(),
+	 * reodering qxl_modeset_fini() + qxl_device_fini() calls is
+	 * non-trivial though.
+	 */
+	qxl_modeset_fini(qdev);

So the drm_mode_config_cleanup call in here belongs in ->release, but the qxl_destroy_monitors_object feels like should be perfectly fine in the remove hook. You might need to sprinkle a few drm_dev_enter/exit around to protect code paths thought.

Aside from this lgtm, for the series

Quoted 9 lines

And up to you whether you want to fix this or not really.

Btw for testing all these patches that add a ->release hook I think it'd be good if the drm core checks that drm_device->dev is set to NULL, and that we do this in the remove hook. Since that's guaranteed to be gone at that point, so anything in ->release that still needs the device is broken. Ofc maybe do that check only for drivers which have a ->release hook, and we might need a few fixups.

We take a ref on the parent device in drm_dev_init() and release it in drm_dev_fini(). I added this because of the DRM_DEV_* macros we have, to protect access to the device struct after it was unregistered. Setting drm_device->dev to NULL in drm_dev_unregister() instead will provide the same protection I think.

commit 56be6503aab2
drm/drv: Hold ref on parent device during drm_device lifetime

Noralf.

Quoted 34 lines

Cheers, Daniel

Quoted 32 lines
drivers/gpu/drm/qxl/qxl_drv.c +8 -7
+	qxl_device_fini(qdev);
+	dev->dev_private = NULL;
+	kfree(qdev);
+}
+
 static void
 qxl_pci_remove(struct pci_dev *pdev)
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
-	struct qxl_device *qdev = dev->dev_private;
 
 	drm_dev_unregister(dev);
-
-	qxl_modeset_fini(qdev);
-	qxl_device_fini(qdev);
+	drm_atomic_helper_shutdown(dev);
 	if (is_vga(pdev))
 		vga_put(pdev, VGA_RSRC_LEGACY_IO);
-
-	dev->dev_private = NULL;
-	kfree(qdev);
 	drm_dev_put(dev);
 }
 
@@ -279,6 +289,8 @@ static struct drm_driver qxl_driver = {
 	.major = 0,
 	.minor = 1,
 	.patchlevel = 0,
+
+	.release = qxl_drm_release,
 };
 
Quoted 5 lines
Quoted 4 lines
drivers/gpu/drm/qxl/qxl_drv.c +0 -0
 static int __init qxl_init(void)
Signature · 1 line
2.18.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel