mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zack Rusin <zack.rusin@broadcom.com>
To: dri-devel@lists.freedesktop.org
Cc: David Airlie <airlied@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Dmitry Osipenko <dmitry.osipenko@collabora.com>,
	Gurchetan Singh <gurchetansingh@chromium.org>,
	Chia-I Wu <olvaffe@gmail.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Simona Vetter <simona@ffwll.ch>,
	virtualization@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 05/12] drm/virtio: Add sysfb restore on probe failure
Date: Mon, 29 Dec 2025 16:58:11 -0500	[thread overview]
Message-ID: <20251229215906.3688205-6-zack.rusin@broadcom.com> (raw)
In-Reply-To: <20251229215906.3688205-1-zack.rusin@broadcom.com>

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 <zack.rusin@broadcom.com>
Cc: David Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Cc: Gurchetan Singh <gurchetansingh@chromium.org>
Cc: Chia-I Wu <olvaffe@gmail.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: virtualization@lists.linux.dev
Cc: linux-kernel@vger.kernel.org
---
 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:
-- 
2.48.1


  parent reply	other threads:[~2025-12-29 21:59 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-29 21:58 [PATCH 00/12] Recover sysfb after DRM " Zack Rusin
2025-12-29 21:58 ` [PATCH 01/12] video/aperture: Add sysfb restore on " Zack Rusin
2025-12-29 21:58 ` [PATCH 02/12] drm/vmwgfx: Use devm aperture helpers for sysfb restore on " Zack Rusin
2025-12-29 21:58 ` [PATCH 03/12] drm/xe: " Zack Rusin
2025-12-29 21:58 ` [PATCH 04/12] drm/amdgpu: " Zack Rusin
2025-12-29 21:58 ` Zack Rusin [this message]
2026-01-15 10:12   ` [PATCH 05/12] drm/virtio: Add " Dmitry Osipenko
2025-12-29 21:58 ` [PATCH 06/12] drm/nouveau: Use devm aperture helpers for " Zack Rusin
2025-12-29 21:58 ` [PATCH 07/12] drm/qxl: " Zack Rusin
2025-12-29 21:58 ` [PATCH 08/12] drm/vboxvideo: " Zack Rusin
2025-12-29 21:58 ` [PATCH 09/12] drm/hyperv: Add " Zack Rusin
2025-12-29 21:58 ` [PATCH 10/12] drm/ast: Use devm aperture helpers for " Zack Rusin
2025-12-29 21:58 ` [PATCH 11/12] drm/radeon: " Zack Rusin
2025-12-29 21:58 ` [PATCH 12/12] drm/i915: " Zack Rusin
2026-01-09 10:34 ` [PATCH 00/12] Recover sysfb after DRM " Thomas Zimmermann
2026-01-10  4:52   ` Zack Rusin
2026-01-15 11:02     ` Thomas Zimmermann
2026-01-15 14:39       ` Christian König
2026-01-15 14:54         ` Thomas Zimmermann
2026-01-15 15:58           ` Christian König
2026-01-15 15:10         ` Ville Syrjälä
2026-01-15 16:36           ` Gerd Hoffmann
2026-01-15 16:39             ` Mario Limonciello
2026-01-16  7:39           ` Thomas Zimmermann
2026-01-16  3:59       ` Zack Rusin
2026-01-16  7:58         ` Thomas Zimmermann
2026-01-17  6:02           ` Zack Rusin
2026-01-19 10:03             ` Christian König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251229215906.3688205-6-zack.rusin@broadcom.com \
    --to=zack.rusin@broadcom.com \
    --cc=airlied@redhat.com \
    --cc=dmitry.osipenko@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gurchetansingh@chromium.org \
    --cc=kraxel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=olvaffe@gmail.com \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®