drm/fb-helper: defer setup when fbdev_probe() fails, not just on -EAGAIN
Subsystems (3)
PATCH 1/1 drm/fb-helper: defer setup when fbdev_probe() fails, not just on -EAGAIN
__drm_fb_helper_initial_config_and_unlock() calls drm_client_modeset_probe() first, which already fills in each mode_set->mode/num_connectors for every connected output, and only afterwards calls drm_fb_helper_single_fb_probe() to create fb_helper->fb and wire it into those mode_sets via drm_setup_crtcs_fb().
If drm_fb_helper_single_fb_probe() fails with anything other than -EAGAIN (e.g. dev->driver->fbdev_probe() itself fails), the function bails out before drm_setup_crtcs_fb() runs and before setting fb_helper->deferred_setup. The client is left with mode_sets that have a mode and connectors but mode_set->fb == NULL, and nothing marks this fb_helper as needing a retry.
__drm_fb_helper_restore_fbdev_mode_unlocked() only skips committing when fb_helper->deferred_setup is set, so a later .restore() call (drm_lastclose() on process exit, in this report) commits the stale mode_set through drm_client_modeset_commit() -> drm_client_modeset_commit_atomic() -> __drm_atomic_helper_set_config(), which hits WARN_ON(!set->fb).
Mark fb_helper->deferred_setup on any drm_fb_helper_single_fb_probe() failure, not just -EAGAIN, so restore keeps skipping the commit until a later hotplug event successfully re-probes and re-populates mode_set->fb. The real error code is still returned to the caller unchanged.
---
Tested in QEMU (KVM, x86_64) with the syzbot C reproducer, which enumerates a USB device over raw-gadget matching drm/gud's ID (idVendor 0x1d50, idProduct 0x614d) then opens the resulting DRM node. In our test VM gud lands on a different card minor than in the syzbot report since other drivers (vgem/vkms/bochs-drm) register first, but retargeting the reproducer's open() at gud's actual minor reproduces it directly on the very first probe:
gud 1-1:1.0: [drm] format XR24 little-endian (0x34325258) not supported gud 1-1:1.0: [drm] No compatible format found
gud 1-1:1.0: [drm] *ERROR* fbdev: Failed to setup emulation (ret=-22)
------------[ cut here ]------------ !set->fb WARNING: drivers/gpu/drm/drm_atomic.c:2031 ...
On the unpatched kernel this isn't benign: __drm_atomic_helper_set_config() warns and then continues, committing an active CRTC/plane with a NULL framebuffer, which escalates into a NULL-pointer dereference and a fatal kernel panic a few lines later in our runs. With this patch applied, the same gud probe failure (ret=-22) still happens every time as expected, but restore() no longer commits the stale mode_set: no warning, no panic, clean shutdown across repeated runs.
drivers/gpu/drm/drm_fb_helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_fb_helper.c +3 -3
@@ -1724,10 +1724,10 @@ __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper *fb_helper) ret =drm_fb_helper_single_fb_probe (fb_helper);if (ret <0 ) { -if (ret == -EAGAIN ) { - fb_helper->deferred_setup = true; +/* modesets are probed but fb_helper->fb isn't; defer restore too */ + fb_helper->deferred_setup = true; +if (ret == -EAGAIN ) ret =0 ; - }mutex_unlock (&fb_helper->lock); goto err_drm_fb_helper_release_info;
Signature · 1 line
2.43.0
Hi
Am 27.09.26 um 09:54 schrieb Nguyen Ngoc Thang:
Quoted 27 lines
__drm_fb_helper_initial_config_and_unlock()callsdrm_client_modeset_probe()first, which already fills in each mode_set->mode/num_connectors for every connected output, and only afterwards callsdrm_fb_helper_single_fb_probe()to createfb_helper->fband wire it into thosemode_setsviadrm_setup_crtcs_fb().If
drm_fb_helper_single_fb_probe()fails with anything other than-EAGAIN(e.g.dev->driver->fbdev_probe()itself fails), the function bails out beforedrm_setup_crtcs_fb()runs and before settingfb_helper->deferred_setup. The client is left withmode_setsthat have a mode and connectors butmode_set->fb== NULL, and nothing marks thisfb_helperas needing a retry.
__drm_fb_helper_restore_fbdev_mode_unlocked()only skips committing whenfb_helper->deferred_setupis set, so a later .restore() call (drm_lastclose()on process exit, in this report) commits the stalemode_setthroughdrm_client_modeset_commit()->drm_client_modeset_commit_atomic()->__drm_atomic_helper_set_config(), which hitsWARN_ON(!set->fb).Mark
fb_helper->deferred_setupon anydrm_fb_helper_single_fb_probe()failure, not just-EAGAIN, so restore keeps skipping the commit until a later hotplug event successfully re-probes and re-populatesmode_set->fb. The real error code is still returned to the caller unchanged.
Quoted 5 lines
Reported-by [email protected]Fixes ca91a2758fce ("drm/fb-helper: Support deferred setup")Signed-off-by Nguyen Ngoc Thang <[email protected]>
Thanks a lot for the fix.
Best regards
Thomas
Quoted 45 lines
---
Tested in QEMU (KVM,x86_64) with the syzbot C reproducer, which enumerates a USB device over raw-gadget matching drm/gud's ID (idVendor0x1d50, idProduct0x614d) then opens the resulting DRM node. In our test VM gud lands on a different card minor than in the syzbot report since other drivers (vgem/vkms/bochs-drm) register first, but retargeting the reproducer'sopen()at gud's actual minor reproduces it directly on the very first probe:gud 1-1:1.0: [drm] format XR24 little-endian (0x34325258) not supported gud 1-1:1.0: [drm] No compatible format found gud 1-1:1.0: [drm] *ERROR* fbdev: Failed to setup emulation (ret=-22) ------------[ cut here ]------------ !set->fb WARNING: drivers/gpu/drm/drm_atomic.c:2031 ...On the unpatched kernel this isn't benign:
__drm_atomic_helper_set_config()warns and then continues, committing an active CRTC/plane with a NULL framebuffer, which escalates into a NULL-pointer dereference and a fatal kernel panic a few lines later in our runs. With this patch applied, the same gud probe failure (ret=-22) still happens every time as expected, butrestore()no longer commits the stalemode_set: no warning, no panic, clean shutdown across repeated runs.drivers/gpu/drm/drm_fb_helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/drm_fb_helper.c +3
-3@@ -1724,10 +1724,10 @@ __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper *fb_helper) ret =drm_fb_helper_single_fb_probe (fb_helper);if (ret <0 ) { -if (ret == -EAGAIN ) { - fb_helper->deferred_setup = true; +/* modesets are probed but fb_helper->fb isn't; defer restore too */ + fb_helper->deferred_setup = true; +if (ret == -EAGAIN ) ret =0 ; - }mutex_unlock (&fb_helper->lock); goto err_drm_fb_helper_release_info;
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)