Skip to contentSkip to conversation

drm/virtio: implement virtio_gpu_shutdown

PATCH In review Gerd Hoffmann 4 participants 6 messages May 7, 2025 – May 26, 2025

Subsystems (4)
lore
Share & tools
lore

Gerd Hoffmann

author maintainer
#0 lore raw

PATCH 1/1 drm/virtio: implement virtio_gpu_shutdown

Calling drm_dev_unplug() is the drm way to say the device is gone and can not be accessed any more.

---
 drivers/gpu/drm/virtio/virtgpu_drv.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.c +4 -4
index e32e680c7197..71c6ccad4b99 100644
@@ -130,10 +130,10 @@ static void virtio_gpu_remove(struct virtio_device *vdev)
 
 static void virtio_gpu_shutdown(struct virtio_device *vdev)
 {
-	/*
-	 * drm does its own synchronization on shutdown.
-	 * Do nothing here, opt out of device reset.
-	 */
+	struct drm_device *dev = vdev->priv;
+
+	/* stop talking to the device */
+	drm_dev_unplug(dev);
 }
 
 static void virtio_gpu_config_changed(struct virtio_device *vdev)
Signature · 1 line
2.49.0
maintainer
#1 lore raw

Hi,

Quoted 17 lines · Gerd Hoffmann

Calling drm_dev_unplug() is the drm way to say the device is gone and can not be accessed any more.

---
 drivers/gpu/drm/virtio/virtgpu_drv.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.c +0 -0
index e32e680c7197..71c6ccad4b99 100644
@@ -130,10 +130,10 @@ static void virtio_gpu_remove(struct virtio_device *vdev)
 

drivers/gpu/drm/virtio/virtgpu_drv.c static void virtio_gpu_remove(struct virtio_device *vdev) · line 136

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +4 -4
 static void virtio_gpu_shutdown(struct virtio_device *vdev)
 {
-	/*
-	 * drm does its own synchronization on shutdown.
-	 * Do nothing here, opt out of device reset.
-	 */
+	struct drm_device *dev = vdev->priv;
+
+	/* stop talking to the device */
+	drm_dev_unplug(dev);

I'm not necessarily opposed to using drm_dev_unplug() here, but it's still pretty surprising to me. It's typically used in remove, not shutdown. The typical helper to use at shutdown is drm_atomic_helper_shutdown.

So if the latter isn't enough or wrong, we should at least document why.

Maxime

author maintainer
#2 lore raw
Quoted 22 lines
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +0 -0
index e32e680c7197..71c6ccad4b99 100644
@@ -130,10 +130,10 @@ static void virtio_gpu_remove(struct virtio_device *vdev)
 

drivers/gpu/drm/virtio/virtgpu_drv.c static void virtio_gpu_remove(struct virtio_device *vdev) · line 136

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +4 -4
 static void virtio_gpu_shutdown(struct virtio_device *vdev)
 {
-	/*
-	 * drm does its own synchronization on shutdown.
-	 * Do nothing here, opt out of device reset.
-	 */
+	struct drm_device *dev = vdev->priv;
+
+	/* stop talking to the device */
+	drm_dev_unplug(dev);

I'm not necessarily opposed to using drm_dev_unplug() here, but it's still pretty surprising to me. It's typically used in remove, not shutdown. The typical helper to use at shutdown is drm_atomic_helper_shutdown.

Quoted 1 line

So if the latter isn't enough or wrong, we should at least document why.

The intention of this is to make sure the driver stops talking to the device (as the comment already says).

There are checks in place in the virt queue functions which will make sure the driver will not try place new requests in the queues after drm_dev_unplug() has been called. Which why I decided to implement it that way.

drm_atomic_helper_shutdown() tears down all outputs according to the documentation. Which is something different. I don't think calling drm_atomic_helper_shutdown() will do what I need here. Calling it in addition to drm_dev_unplug() might make sense, not sure.

Suggestions are welcome.

take care,
Gerd

#3 lore raw
Quoted 37 lines · Gerd Hoffmann
Quoted 22 lines
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +0 -0
index e32e680c7197..71c6ccad4b99 100644
@@ -130,10 +130,10 @@ static void virtio_gpu_remove(struct virtio_device *vdev)
 

drivers/gpu/drm/virtio/virtgpu_drv.c static void virtio_gpu_remove(struct virtio_device *vdev) · line 136

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +4 -4
 static void virtio_gpu_shutdown(struct virtio_device *vdev)
 {
-	/*
-	 * drm does its own synchronization on shutdown.
-	 * Do nothing here, opt out of device reset.
-	 */
+	struct drm_device *dev = vdev->priv;
+
+	/* stop talking to the device */
+	drm_dev_unplug(dev);

I'm not necessarily opposed to using drm_dev_unplug() here, but it's still pretty surprising to me. It's typically used in remove, not shutdown. The typical helper to use at shutdown is drm_atomic_helper_shutdown.

Quoted 1 line

So if the latter isn't enough or wrong, we should at least document why.

The intention of this is to make sure the driver stops talking to the device (as the comment already says).

There are checks in place in the virt queue functions which will make sure the driver will not try place new requests in the queues after drm_dev_unplug() has been called. Which why I decided to implement it that way.

drm_atomic_helper_shutdown() tears down all outputs according to the documentation. Which is something different. I don't think calling drm_atomic_helper_shutdown() will do what I need here. Calling it in addition to drm_dev_unplug() might make sense, not sure.

Quoted 4 lines

Suggestions are welcome.

take care,
Gerd

I suggest adding comments in code explaining why it's approriate here. Want to try?

Signature · 1 line
MST
maintainer
#4 lore raw
Quoted 38 lines · Michael S. Tsirkin
Quoted 37 lines · Gerd Hoffmann
Quoted 22 lines
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +0 -0
index e32e680c7197..71c6ccad4b99 100644
@@ -130,10 +130,10 @@ static void virtio_gpu_remove(struct virtio_device *vdev)
 

drivers/gpu/drm/virtio/virtgpu_drv.c static void virtio_gpu_remove(struct virtio_device *vdev) · line 136

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +4 -4
 static void virtio_gpu_shutdown(struct virtio_device *vdev)
 {
-	/*
-	 * drm does its own synchronization on shutdown.
-	 * Do nothing here, opt out of device reset.
-	 */
+	struct drm_device *dev = vdev->priv;
+
+	/* stop talking to the device */
+	drm_dev_unplug(dev);

I'm not necessarily opposed to using drm_dev_unplug() here, but it's still pretty surprising to me. It's typically used in remove, not shutdown. The typical helper to use at shutdown is drm_atomic_helper_shutdown.

Quoted 1 line

So if the latter isn't enough or wrong, we should at least document why.

The intention of this is to make sure the driver stops talking to the device (as the comment already says).

There are checks in place in the virt queue functions which will make sure the driver will not try place new requests in the queues after drm_dev_unplug() has been called. Which why I decided to implement it that way.

drm_atomic_helper_shutdown() tears down all outputs according to the documentation. Which is something different. I don't think calling drm_atomic_helper_shutdown() will do what I need here. Calling it in addition to drm_dev_unplug() might make sense, not sure.

Quoted 8 lines
Quoted 4 lines

Suggestions are welcome.

take care,
Gerd

I suggest adding comments in code explaining why it's approriate here. Want to try?

Yes, that would be great

Maxime

maintainer
#5 lore raw
In reply to Gerd Hoffmann
Quoted 20 lines · Gerd Hoffmann

Calling drm_dev_unplug() is the drm way to say the device is gone and can not be accessed any more.

---
 drivers/gpu/drm/virtio/virtgpu_drv.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.c +0 -1
index e32e680c7197..71c6ccad4b99 100644
@@ -130,10 +130,10 @@ static void virtio_gpu_remove(struct virtio_device *vdev)
 
 static void virtio_gpu_shutdown(struct virtio_device *vdev)
 {
-	/*

drivers/gpu/drm/virtio/virtgpu_drv.c static void virtio_gpu_remove(struct virtio_device *vdev) · line 139

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +4 -3
-	 * drm does its own synchronization on shutdown.
-	 * Do nothing here, opt out of device reset.
-	 */
+	struct drm_device *dev = vdev->priv;
+
+	/* stop talking to the device */
+	drm_dev_unplug(dev);
 }
 
 static void virtio_gpu_config_changed(struct virtio_device *vdev)

Could you please describe whether this patch is fixing a specific problem or it's a generic improvement for avoiding potential problems on shutdown.

Signature · 2 lines
Best regards,
Dmitry