From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 241781F4C98; Mon, 4 Aug 2025 00:41:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754268089; cv=none; b=l/hjMxuMPrHBAfRFASbeHb8yIj3iOEBbvw9WceOatUHXTzY/pJenobpYMdxDDWE4smzDuw9Zg2EdTNNhbYa4zQb1Pa0Si/sNSRFaKgWnD5c3HfQ1PPFaMIa/bepJPazXVk7a9i9BYSZVEYdtTJlQ97Y1Tw0HZdouyEu6HLXlPMM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754268089; c=relaxed/simple; bh=OxKNcqewlJuWFNCRUA6yktG1W19uNKAs95onhupDJlc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FLZiSJ1+aU+Ba1TtHI8T0KG3oX4JMpvUHhPRCM10arbNyazcrAm1HmbdemGMJBQHQrG99eTbz6PRhfAdP2iozVy/LzcGqwRKjbo8rw/+c8qxm7BlfS6hH142RjrkJ4efkNB1oqkDanGJoVVnnWyLYVMv2RTaKMN2FA4zSYSamh8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z15eVQQN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z15eVQQN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD546C4CEEB; Mon, 4 Aug 2025 00:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754268089; bh=OxKNcqewlJuWFNCRUA6yktG1W19uNKAs95onhupDJlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z15eVQQNdk8RQLrqNPlqqCGh4RwgKXs50GMRMwKQY2Lo56a8szeOT9hKBerg0jkFQ qpdv3AWzR3kM8uai7COiB70LHUPfiOvcdzX3bInsqxf+DzSxv447N5TSgTrG70Wspt 718GhsQ7ZEqxwwo93gp1zhr4OF4JczLHhTjDSZueQ5bBFFKht/ufMl8OXjcp/GL8Jb hJ+xhg97hlwGxwBC3ShVdm0+sdNN9lb3jYC+M4UdGJBdDGy5rR7kbKBt51AGeejQud ETSW63iXZ8zENvrrHTyWLlML9H+afMtCKzYawvkQED7L2NWmwGuAYAeyL931/Qo/Cj ypzmGH4SztQmg== From: Sasha Levin To: patches@lists.linux.dev, stable@vger.kernel.org Cc: tuhaowen , "Rafael J . Wysocki" , Sasha Levin , rafael@kernel.org, linux-pm@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 19/39] PM: sleep: console: Fix the black screen issue Date: Sun, 3 Aug 2025 20:40:21 -0400 Message-Id: <20250804004041.3628812-19-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250804004041.3628812-1-sashal@kernel.org> References: <20250804004041.3628812-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.240 Content-Transfer-Encoding: 8bit From: tuhaowen [ Upstream commit 4266e8fa56d3d982bf451d382a410b9db432015c ] When the computer enters sleep status without a monitor connected, the system switches the console to the virtual terminal tty63(SUSPEND_CONSOLE). If a monitor is subsequently connected before waking up, the system skips the required VT restoration process during wake-up, leaving the console on tty63 instead of switching back to tty1. To fix this issue, a global flag vt_switch_done is introduced to record whether the system has successfully switched to the suspend console via vt_move_to_console() during suspend. If the switch was completed, vt_switch_done is set to 1. Later during resume, this flag is checked to ensure that the original console is restored properly by calling vt_move_to_console(orig_fgconsole, 0). This prevents scenarios where the resume logic skips console restoration due to incorrect detection of the console state, especially when a monitor is reconnected before waking up. Signed-off-by: tuhaowen Link: https://patch.msgid.link/20250611032345.29962-1-tuhaowen@uniontech.com Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- LLM Generated explanations, may be completely bogus: **Backport Status: YES** This commit should be backported to stable kernel trees. Here's my extensive analysis: **1. Bug Fix Nature:** The commit fixes a clear user-visible bug - a black screen issue that occurs when: - A computer enters sleep without a monitor connected - A monitor is connected while the system is asleep - Upon wake, the console remains on tty63 (SUSPEND_CONSOLE) instead of returning to tty1 This is a functional regression that impacts user experience, making the system appear unresponsive or broken after resume. **2. Small and Contained Fix:** The fix is minimal and well-contained: - Adds a single `static bool vt_switch_done` flag - Modifies only two functions: `pm_prepare_console()` and `pm_restore_console()` - Total change is just 6 lines of code (excluding whitespace) - The logic is straightforward: track whether VT switch happened during suspend, and ensure restoration happens during resume **3. Low Risk of Side Effects:** The change has minimal risk: - The new flag (`vt_switch_done`) is only set when `vt_move_to_console()` succeeds - The restoration logic preserves existing behavior when `pm_vt_switch()` returns true - The fix only adds an additional condition `!vt_switch_done` to ensure restoration happens even when `pm_vt_switch()` returns false during resume - No architectural changes or new features are introduced **4. Critical Subsystem but Safe Change:** While this touches the PM/console subsystem (critical for suspend/resume), the change is safe: - It doesn't modify the core VT switching mechanism - It only ensures the existing restoration path is executed when needed - The file has been stable since 2013 (last major change was f43f627d2f17e) **5. Clear Problem Description:** The commit message clearly describes: - The specific scenario that triggers the bug - The root cause (skipped VT restoration) - The solution (tracking VT switch state) **6. Follows Stable Rules:** This aligns perfectly with stable tree criteria: - Fixes a real bug affecting users - Minimal change (6 lines) - No new features - Clear fix for a specific problem - Low regression risk The commit addresses a real-world scenario where users connecting monitors to sleeping systems experience black screens upon wake - a frustrating issue that makes systems appear broken. The fix is surgical, adding only the minimum tracking needed to ensure proper console restoration. kernel/power/console.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/power/console.c b/kernel/power/console.c index fcdf0e14a47d..19c48aa5355d 100644 --- a/kernel/power/console.c +++ b/kernel/power/console.c @@ -16,6 +16,7 @@ #define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1) static int orig_fgconsole, orig_kmsg; +static bool vt_switch_done; static DEFINE_MUTEX(vt_switch_mutex); @@ -136,17 +137,21 @@ void pm_prepare_console(void) if (orig_fgconsole < 0) return; + vt_switch_done = true; + orig_kmsg = vt_kmsg_redirect(SUSPEND_CONSOLE); return; } void pm_restore_console(void) { - if (!pm_vt_switch()) + if (!pm_vt_switch() && !vt_switch_done) return; if (orig_fgconsole >= 0) { vt_move_to_console(orig_fgconsole, 0); vt_kmsg_redirect(orig_kmsg); } + + vt_switch_done = false; } -- 2.39.5