From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.51.188.92 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796488423; b=QUx+swhUM+KgVM1AqDrkSoVfaYKiD223e8Se3uJATd5SMncwx75u3RDFoiOdCr0Ragdv 58g/BaYKOa0DbpR2i8G6NJVz2Ypog/4fM91TU/04D4+DIZt2OdytVQK6L8HubMtnOnL79 oGL7rr4tr4D56/8WWV7rO94+tN5lQNAjn62RYqC8THU+N8o+jMhZ34l+4QBa9yXXjTpbT m2zgC4VL3lXfQsLwesFLuoJvRPKlbcF1HPtauxMcVoK7QizwlXxytZfjKPdBRQc/dKaA5 3CJ4Zt6kBuHIwxbbELhMAFBXtJOR4r1aFzDX6jSEFJKvzkBP0K4dj0N5qlSxnpsSADw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796488423; h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date: Message-ID:User-Agent:MIME-Version:Content-Type; bh=uCzQai7wxp8eOtWHH8EnvSueDqeNPtbvp37IVm2JB1A=; b=oP7osl5J3Ttispd+97WN9EUPNfgQHpi3mE8xfFwC/2ZH/MzBojlyjgE8OKGVNZTEYw9y /ztEip2GIZPgf5Pu088ZI7oY43BolCXSjjwyNx0R8RJ9Xgx9QdZcSVU9uDWMxJz4T4HNf uwKAyggk/SbwZAMjzMLzbVjiDqxjCreCD46plhP4mrbW37fGEnTv3CPDtjMzu3+z7/E6v Yu/VM/zM293xkT6zcOJmfBxpzzx3ck7nFaRgUjSeTFfryVv0MKORFeRXMT0L7DcqLGrvT jLtm7pFMIEnWiyNU2WKNZZBtQQykw17vGu6GS7CrQ630sjIQnXx+3hbeQnhAoSHC1Gg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gnu.org; spf=pass smtp.mailfrom=gnu.org; dkim=pass header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=sLYhWmM8; arc=none smtp.remote-ip=209.51.188.92 Received: from eggs.gnu.org (eggs.gnu.org [209.51.188.92]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E035606A31F for ; Sat, 5 Dec 2026 16:33:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3E035606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gnu.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=sLYhWmM8 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZshd-0005CI-28; Sat, 05 Dec 2026 11:33:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=uCzQai7wxp8eOtWHH8EnvSueDqeNPtbvp37IVm2JB1A=; b=sLYhWmM8S4jI2h BHDjJQC1qSjbKlE56DFrWIs/VJjICeP2v9wwPO3MuFo0y8Vx8NakzZEQc06hzozNcU1kbLhTniuKR UpEfii16cjtJIRETEjIy0zwVvqOSh32XbZQBn6hTFr09yCe/9OpCfBSWciu/2HPhr24G6OjIukQ2N E9pjqHyuIiJELFerX0OzA4lDODrsVgu02mVSxG25tYWngEKFu9x08zUC0PrIikIcnN24jYePLwonf YCvlsAVbSvsntkSho+A7KABCSWh0PiQvkgZ38uyMe+ETg3imHf5vU1XSteA4Kpt/a/wgPqvrqqXiS f509BXaOOR4KFh9GrwVQ==; From: Anush Veeranala To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: David Airlie , Simona Vetter , Rob Clark , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] drm/fb-helper: Keep blanked outputs off across restore and hotplug Date: Sat, 05 Dec 2026 22:03:15 +0530 Message-ID: <87fqwbit6c.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain 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. The mode is remembered even when a DRM master makes the request's commit fail, since fbcon counts the console blanked or unblanked all the same, and the next restore applies it. Forced restores still light the outputs, and set the remembered mode to on so that the restores after them keep the outputs lit: 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 --- Notes: Changes in v2: - Set the remembered mode to on at forced restores, which Sashiko's review of v1 found missing. v1 kept the last blank's mode, so a restore after a forced one turned the outputs off again: at once, the delayed hotplug that sysrq's restore runs, and, after an FBIOBLANK in graphics mode, which fbcon ignores, the device's close that followed the switch back to text mode, on a console that counted itself unblanked. - Comment why a request's mode is remembered when its commit fails. Remembering it only on success, as the review also suggested, lit the outputs at the close after a blank refused while a program held the device, on a blanked console, and left them off at the close after an unblank refused the same way, on an unblanked one. v1: https://lore.kernel.org/r/875wx7rfwp.fsf@gnu.org 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, and the program holding the device open, as its first opener and so its DRM master, for a compositor or fwupd. outputs after before v1 v2 the console blanked off off off the device's last user closed it on off off a display was plugged in on off off an unblank, as a keypress does on on on a switch to KD_GRAPHICS and back to KD_TEXT with the device held, as Xorg exits, then its close on on on another display was plugged in, blanked again on off off a blank with the device held, then its close on off off an unblank with the device held, then its close on on on FBIOBLANK in KD_GRAPHICS with the device held, back to KD_TEXT, then its close on off on a display plugged in with the device held, its master dropped, then sysrq v on off on "Off" means every CRTC's active was 0, "on" that every enabled CRTC's was 1. The console counted itself unblanked after the unblanks and the switches back to KD_TEXT, and blanked after every other row, the sysrq row included, on all three. After each unblank, the CRTCs of the displays plugged in while blanked were on as well. Each kernel logged the same three warnings at boot, none from DRM, and no others. 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 | 27 +++++++++++++++++++++- include/drm/clients/drm_fbdev_helper.h | 12 ++++++++++ 2 files changed, 38 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..9b8fec332 100644 --- a/drivers/gpu/drm/clients/drm_fbdev_helper.c +++ b/drivers/gpu/drm/clients/drm_fbdev_helper.c @@ -105,6 +105,22 @@ __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); + /* + * Forced restores light the outputs, blanked or not: fbcon + * forces one when switching back to text mode and then + * unblanks, and sysrq forces one to show the console. Later + * restores, such as the delayed hotplug's below, keep them on. + */ + fb_helper->dpms_mode = DRM_MODE_DPMS_ON; + } else if (fb_helper->dpms_mode != DRM_MODE_DPMS_ON && + drm_drv_uses_atomic_modeset(fb_helper->dev)) { + /* + * Keep blanked outputs off. 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 +146,9 @@ __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, which turns them on until the next + * blank request. * * Returns: * 0 on success, or a negative errno code otherwise. @@ -146,6 +164,12 @@ 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); + /* + * Record the mode even when a DRM master makes the commit fail: fbcon + * counts the console blanked or unblanked all the same, and the next + * restore applies it. + */ + fb_helper->dpms_mode = dpms_mode; drm_client_modeset_dpms(&fb_helper->client, dpms_mode); mutex_unlock(&fb_helper->lock); } @@ -372,6 +396,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..529d70c5d 100644 --- a/include/drm/clients/drm_fbdev_helper.h +++ b/include/drm/clients/drm_fbdev_helper.h @@ -187,6 +187,18 @@ struct drm_fb_helper { */ bool deferred_setup; + /** + * @dpms_mode: + * + * DPMS mode of the last blank request, or %DRM_MODE_DPMS_ON after a + * forced restore. 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