On 12/30/25 00:58, Zack Rusin wrote:
> Register a devm action on the virtio device to restore the system
> framebuffer (efifb/simpledrm) if the driver's probe fails after
> removing the firmware framebuffer.
> 
> Unlike PCI drivers, virtio-gpu cannot use the
> devm_aperture_remove_conflicting_pci_devices() helper because the
> PCI device is managed by the virtio-pci driver, not by virtio-gpu.
> When virtio-gpu probe fails, the PCI device remains bound to
> virtio-pci, so devm actions registered on the PCI device won't fire.
> 
> Instead, register the sysfb restore action on the virtio device
> (&vdev->dev) which will be released if virtio-gpu probe fails.
> Cancel the action after successful probe since the driver is now
> responsible for display output.
> 
> This only applies to VGA devices where 
> aperture_remove_conflicting_pci_devices()
> is called to remove the firmware framebuffer.
> 
> Signed-off-by: Zack Rusin <[email protected]>
> Cc: David Airlie <[email protected]>
> Cc: Gerd Hoffmann <[email protected]>
> Cc: Dmitry Osipenko <[email protected]>
> Cc: Gurchetan Singh <[email protected]>
> Cc: Chia-I Wu <[email protected]>
> Cc: Maarten Lankhorst <[email protected]>
> Cc: Maxime Ripard <[email protected]>
> Cc: Thomas Zimmermann <[email protected]>
> Cc: Simona Vetter <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> ---
>  drivers/gpu/drm/virtio/virtgpu_drv.c | 29 ++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.c 
> b/drivers/gpu/drm/virtio/virtgpu_drv.c
> index a5ce96fb8a1d..13cc8396fc78 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_drv.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_drv.c
> @@ -30,6 +30,7 @@
>  #include <linux/module.h>
>  #include <linux/pci.h>
>  #include <linux/poll.h>
> +#include <linux/sysfb.h>
>  #include <linux/vgaarb.h>
>  #include <linux/wait.h>
>  
> @@ -52,6 +53,11 @@ static int virtio_gpu_modeset = -1;
>  MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
>  module_param_named(modeset, virtio_gpu_modeset, int, 0400);
>  
> +static void virtio_gpu_restore_sysfb(void *unused)
> +{
> +     sysfb_restore();
> +}
> +
>  static int virtio_gpu_pci_quirk(struct drm_device *dev)
>  {
>       struct pci_dev *pdev = to_pci_dev(dev->dev);
> @@ -75,6 +81,7 @@ static int virtio_gpu_probe(struct virtio_device *vdev)
>  {
>       struct drm_device *dev;
>       int ret;
> +     bool sysfb_restore_registered = false;
>  
>       if (drm_firmware_drivers_only() && virtio_gpu_modeset == -1)
>               return -EINVAL;
> @@ -97,6 +104,21 @@ static int virtio_gpu_probe(struct virtio_device *vdev)
>               ret = virtio_gpu_pci_quirk(dev);
>               if (ret)
>                       goto err_free;
> +
> +             /*
> +              * For VGA devices, register sysfb restore on the virtio device.
> +              * We can't use devm_aperture_remove_conflicting_pci_devices()
> +              * because the PCI device is managed by virtio-pci, not us.
> +              * Register on &vdev->dev so it fires if our probe fails.
> +              */
> +             if (pci_is_vga(to_pci_dev(vdev->dev.parent))) {
> +                     ret = devm_add_action_or_reset(&vdev->dev,
> +                                                    virtio_gpu_restore_sysfb,
> +                                                    NULL);
> +                     if (ret)
> +                             goto err_free;
> +                     sysfb_restore_registered = true;
> +             }
>       }
>  
>       dma_set_max_seg_size(dev->dev, dma_max_mapping_size(dev->dev) ?: 
> UINT_MAX);
> @@ -110,6 +132,13 @@ static int virtio_gpu_probe(struct virtio_device *vdev)
>  
>       drm_client_setup(vdev->priv, NULL);
>  
> +     /*
> +      * Probe succeeded - cancel sysfb restore. We're now responsible
> +      * for display output.
> +      */
> +     if (sysfb_restore_registered)
> +             devm_remove_action(&vdev->dev, virtio_gpu_restore_sysfb, NULL);
> +
>       return 0;
>  
>  err_deinit:

Acked-by: Dmitry Osipenko <[email protected]>

-- 
Best regards,
Dmitry

Reply via email to