All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/fb-helper: Keep blanked outputs off across restore and hotplug
@ 2026-12-05 13:55 Anush Veeranala
  2026-12-05 14:31 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Anush Veeranala @ 2026-12-05 13:55 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann
  Cc: David Airlie, Simona Vetter, Rob Clark, dri-devel, linux-kernel

When fbcon blanks the console, drm_fb_helper_blank() commits the fbdev
client's modeset with the CRTCs inactive. Two events commit that
modeset again with the CRTCs active: a restore, which drm_lastclose()
runs when the device's last user closes it, and a hotplug event, which
ends in one. fbcon isn't told and still counts the console as blanked,
so it doesn't blank it again, and consoleblank's timer, which runs only
while the console is unblanked, doesn't restart. The display stays on
until a key is pressed.

Opening and closing the DRM device, as fwupd does to read the screen
size, or plugging in a display is enough. On a laptop serving headless
with its lid closed, the internal panel then stays lit indefinitely.

Remember the DPMS mode of the last blank request in the fb helper, and
have unforced restores on atomic drivers commit in that mode through
drm_client_modeset_dpms(), so the outputs of a blanked fbdev stay off
until it is unblanked. A hotplug's restore isn't forced, so this covers
hotplugs too. Forced restores still light the outputs: fbcon forces
one when switching back to text mode and unblanks right after, an
unblank that can't commit while the previous DRM master, such as Xorg,
still holds the device, and sysrq forces one to show the console.

Legacy drivers keep committing with the outputs on, since their DPMS
only sets the connectors' DPMS property and wouldn't apply a
configuration that a hotplug changed.

Claude Code (Claude Opus 5.5) found the cause and wrote this patch and
its description, in a session I started to find out why a blanked
laptop panel stayed lit.

Fixes: bbb1e52402b2 ("drm/fb-helper: atomic restore_fbdev_mode()..")
Signed-off-by: Anush Veeranala <j@gnu.org>
---

Notes:
    I tested this on drm-misc-next at b5a1ab58fb65 in QEMU 10.0.13 with
    its qxl display, consoleblank=6, and PREEMPT, PROVE_LOCKING and
    DEBUG_ATOMIC_SLEEP on. A program running as init read each CRTC's
    active from debugfs's atomic state, and the console's blank with
    TIOCL_BLANKEDSCREEN, after each step. Writing "on" to a connector's
    status in sysfs stood in for plugging in a display.
    
      outputs after                                       before   after
      the console blanked                                 off      off
      the device's last user closed it                    on       off
      a display was plugged in                            on       off
      an unblank, as a keypress does                      on       on
      a switch to KD_GRAPHICS and back to KD_TEXT with
      the device held, as Xorg exits, then its close      on       on
      another display was plugged in, blanked again       on       off
    
    "Off" means every CRTC's active was 0, "on" that every enabled CRTC's
    was 1. The console counted itself blanked in every row but the unblank
    and the switch back to text mode, before and after. After each
    unblank, the CRTCs of the displays plugged in while blanked were on as
    well. The kernel logged no warnings. Not tested: legacy (non-atomic)
    drivers, which this leaves unchanged, and real hardware.
    
    To reproduce from a serial console or SSH, as a keypress on the
    console unblanks it, once the console has blanked:
    
      grep active= /sys/kernel/debug/dri/0/state   # active=0
      : <> /dev/dri/card0                          # open and close it
      grep active= /sys/kernel/debug/dri/0/state   # active=1
    
    Claude Code also wrote the program I tested with.

 drivers/gpu/drm/clients/drm_fbdev_helper.c | 16 +++++++++++++++-
 include/drm/clients/drm_fbdev_helper.h     | 11 +++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/clients/drm_fbdev_helper.c b/drivers/gpu/drm/clients/drm_fbdev_helper.c
index 415764ee0..592b1f23c 100644
--- a/drivers/gpu/drm/clients/drm_fbdev_helper.c
+++ b/drivers/gpu/drm/clients/drm_fbdev_helper.c
@@ -105,6 +105,17 @@ __drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper,
 		 * racing here, see drm_fb_helper_set_par().
 		 */
 		ret = drm_client_modeset_commit_locked(&fb_helper->client);
+	} else if (fb_helper->dpms_mode != DRM_MODE_DPMS_ON &&
+		   drm_drv_uses_atomic_modeset(fb_helper->dev)) {
+		/*
+		 * Keep blanked outputs off. Forced restores still light them:
+		 * fbcon forces one when switching back to text mode and then
+		 * unblanks, and sysrq forces one to show the console. Legacy
+		 * DPMS doesn't commit the configuration, so legacy drivers
+		 * keep committing it with the outputs on.
+		 */
+		ret = drm_client_modeset_dpms(&fb_helper->client,
+					      fb_helper->dpms_mode);
 	} else {
 		ret = drm_client_modeset_commit(&fb_helper->client);
 	}
@@ -130,7 +141,8 @@ __drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper,
  *
  * This helper should be called from fbdev emulation's &drm_client_funcs.restore
  * callback. It ensures that the user isn't greeted with a black screen when the
- * userspace compositor releases the display device.
+ * userspace compositor releases the display device. If fbdev is blanked, the
+ * outputs stay off unless @force is set.
  *
  * Returns:
  * 0 on success, or a negative errno code otherwise.
@@ -146,6 +158,7 @@ static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
 	struct drm_fb_helper *fb_helper = info->par;
 
 	mutex_lock(&fb_helper->lock);
+	fb_helper->dpms_mode = dpms_mode;
 	drm_client_modeset_dpms(&fb_helper->client, dpms_mode);
 	mutex_unlock(&fb_helper->lock);
 }
@@ -372,6 +385,7 @@ void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
 	helper->funcs = funcs;
 	helper->dev = dev;
 	helper->preferred_bpp = preferred_bpp;
+	helper->dpms_mode = DRM_MODE_DPMS_ON;
 }
 EXPORT_SYMBOL(drm_fb_helper_prepare);
 
diff --git a/include/drm/clients/drm_fbdev_helper.h b/include/drm/clients/drm_fbdev_helper.h
index 7575aaf34..3b02c336d 100644
--- a/include/drm/clients/drm_fbdev_helper.h
+++ b/include/drm/clients/drm_fbdev_helper.h
@@ -187,6 +187,17 @@ struct drm_fb_helper {
 	 */
 	bool deferred_setup;
 
+	/**
+	 * @dpms_mode:
+	 *
+	 * DPMS mode of the last blank request. Unless forced, restores on
+	 * atomic drivers keep the outputs in this mode, as nothing tells
+	 * fbcon that a restore turned them on.
+	 *
+	 * Protected by @lock.
+	 */
+	int dpms_mode;
+
 	/**
 	 * @preferred_bpp:
 	 *

base-commit: b5a1ab58fb6535064d79c26f3d53936e88769339
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/fb-helper: Keep blanked outputs off across restore and hotplug
  2026-12-05 13:55 [PATCH] drm/fb-helper: Keep blanked outputs off across restore and hotplug Anush Veeranala
@ 2026-12-05 14:31 ` sashiko-bot
  2026-12-05 16:40   ` Anush V
  0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-12-05 14:31 UTC (permalink / raw)
  To: Anush Veeranala; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/fb-helper: drm_fb_helper_dpms() latches dpms_mode despite
  -EBUSY failure
- [Medium] drm/fb-helper: forced restore leaves dpms_mode stale across
  delayed hotplug
--

commit 5438bb76521b1ee953b8205afd87e275ec4f45c5
Author: Anush Veeranala <j@gnu.org>

drm/fb-helper: Keep blanked outputs off across restore and hotplug

This commit caches the last DPMS blank mode in struct drm_fb_helper and uses
drm_client_modeset_dpms() on unforced atomic restores so blanked outputs stay
off across drm_lastclose() and hotplug events.

> diff --git a/drivers/gpu/drm/clients/drm_fbdev_helper.c b/drivers/gpu/drm/clients/drm_fbdev_helper.c
> index 415764ee086a8..592b1f23cee63 100644
> --- a/drivers/gpu/drm/clients/drm_fbdev_helper.c
> +++ b/drivers/gpu/drm/clients/drm_fbdev_helper.c
> @@ -105,6 +105,17 @@ __drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper,
>  		 * racing here, see drm_fb_helper_set_par().
>  		 */
>  		ret = drm_client_modeset_commit_locked(&fb_helper->client);
> +	} else if (fb_helper->dpms_mode != DRM_MODE_DPMS_ON &&
> +		   drm_drv_uses_atomic_modeset(fb_helper->dev)) {
> +		/*
> +		 * Keep blanked outputs off. Forced restores still light them:
> +		 * fbcon forces one when switching back to text mode and then
> +		 * unblanks, and sysrq forces one to show the console. Legacy
> +		 * DPMS doesn't commit the configuration, so legacy drivers
> +		 * keep committing it with the outputs on.
> +		 */
> +		ret = drm_client_modeset_dpms(&fb_helper->client,
> +					      fb_helper->dpms_mode);
>  	} else {
>  		ret = drm_client_modeset_commit(&fb_helper->client);
>  	}

[Severity: Medium]
Should the forced restore branch reset fb_helper->dpms_mode to
DRM_MODE_DPMS_ON on success?

If the console is blanked and fb_helper->delayed_hotplug was set while a DRM
master was active, a SysRq-v forced restore lights the outputs via
drm_client_modeset_commit_locked() and then immediately runs
drm_fb_helper_hotplug_event() -> drm_fb_helper_set_par().

That calls __drm_fb_helper_restore_fbdev_mode_unlocked() with force unset,
so the stale fb_helper->dpms_mode commits the CRTCs back off before SysRq-v
finishes, defeating the emergency restore.

[ ... ]

> @@ -146,6 +158,7 @@ static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
>  	struct drm_fb_helper *fb_helper = info->par;
>  
>  	mutex_lock(&fb_helper->lock);
> +	fb_helper->dpms_mode = dpms_mode;
>  	drm_client_modeset_dpms(&fb_helper->client, dpms_mode);
>  	mutex_unlock(&fb_helper->lock);
>  }

[Severity: Medium]
Can drm_fb_helper_dpms() latch fb_helper->dpms_mode even when
drm_client_modeset_dpms() fails with -EBUSY?

If userspace issues FBIOBLANK while a compositor holds DRM master in
KD_GRAPHICS, drm_client_modeset_dpms() returns -EBUSY without changing the
display.  fbcon_fb_blanked() ignores the notification in KD_GRAPHICS, so
par->blank_state stays FB_BLANK_UNBLANK while fb_helper->dpms_mode is stale.

When the compositor exits to KD_TEXT, fbcon_unblank() clears console_blanked
and skips fb_blank(info, FB_BLANK_UNBLANK) because par->blank_state is
already unblanked.  drm_lastclose() then runs an unforced restore and turns
all CRTCs off on a console that keypresses cannot wake.

Updating fb_helper->dpms_mode only when drm_client_modeset_dpms() returns 0
would avoid latching a failed blank request.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/875wx7rfwp.fsf@gnu.org?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/fb-helper: Keep blanked outputs off across restore and hotplug
  2026-12-05 14:31 ` sashiko-bot
@ 2026-12-05 16:40   ` Anush V
  0 siblings, 0 replies; 3+ messages in thread
From: Anush V @ 2026-12-05 16:40 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: dri-devel

> From: sashiko-bot@kernel.org
> Date: Sat,  5 Dec 2026 14:31:21 +0000

> Should the forced restore branch reset fb_helper->dpms_mode to
> DRM_MODE_DPMS_ON on success?

Yes. v2 sets it at every forced restore, whatever the commit returns,
as the field records what fbdev asked for rather than what the
hardware did. The outputs then stay lit through the delayed hotplug
that sysrq's restore runs, where v1 turned them off again, as you
describe.

> Can drm_fb_helper_dpms() latch fb_helper->dpms_mode even when
> drm_client_modeset_dpms() fails with -EBUSY?

It can, and with v1 the close in your scenario turned the outputs off.
In v2 the switch back to KD_TEXT forces a restore, which now sets the
mode to on, so the close leaves them lit.

> Updating fb_helper->dpms_mode only when drm_client_modeset_dpms() returns 0
> would avoid latching a failed blank request.

It would also lose requests fbcon has acted on. In KD_TEXT, fbcon
counts a blank or an unblank as done even when a program holding the
device, such as fwupd, makes its commit fail, and the restore at that
program's close is then the only commit left to apply it. With the mode
updated only on success, that close lit the outputs after a refused
blank, on a console counting itself blanked, and left them dark after a
refused unblank, on one counting itself unblanked, which keypresses
can't wake either. v2 keeps recording the mode, and a comment says why.

v2 is "[PATCH v2] drm/fb-helper: Keep blanked outputs off across
restore and hotplug", in a new thread.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-05 16:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 13:55 [PATCH] drm/fb-helper: Keep blanked outputs off across restore and hotplug Anush Veeranala
2026-12-05 14:31 ` sashiko-bot
2026-12-05 16:40   ` Anush V

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.