From nobody Sun Feb 8 07:14:42 2026 Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) (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 35AF010E5; Tue, 3 Jun 2025 01:02:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.206.16.166 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748912578; cv=none; b=LGr/S01uQOILWbgftQ/3dA3zU084BraBSgPfX6rg/p0kjHx43QWy0zBSsUnLJVeet6sYuSjQNdZqYJSftfynlcrXjD7v1fgUp3XgrAut9CK+X/auA0oi0Ib68Co2FvWIA5PXCsATKeN1B2GiHRLwlHpQlLUS2GW8l1w5N5wuLG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748912578; c=relaxed/simple; bh=fyPQ/mfs2CSaeT6RM8/3j9A3OgCvFV5ebkXfbNQ6tqA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XvTPiYjOCe9Q7CQOdqlT6CGY27bD3jWxyeknXWZZjfn0k/fyUWR01v0s0N/DdXHu/2eRXaloeEeN7dLumSlJwX+JYtZEY6CPQ/gB24FTiL+JHCA1DT4rT0/d9Ca3Z8x5jZ42hqZJ2lSVy4A7iFnM0KG55k0bvFrzxEpOLwpIF3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com; spf=pass smtp.mailfrom=uniontech.com; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b=LppgaXle; arc=none smtp.client-ip=54.206.16.166 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniontech.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b="LppgaXle" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1748912532; bh=A93XqZVqVhYz+KFT6k3LBe2oQch3w3UxJ0GXN9kjeh4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=LppgaXle1ssr0tAAQM/r2gVUSDJDYrpA/5RZ3VgF1ubcANm50K9XKw4fyBjUobOi3 JDN7uhnQ0SR68uuRuoHB22OverKxBRbSUDHf6WJPae0zL4168qk5t3GwJC8S7O0CVW sYaMotoMSoOMDJC0hR3+lE1JsKb45y1rdNDFOLOA= X-QQ-mid: zesmtpip4t1748912524taa33fcd8 X-QQ-Originating-IP: lF+E614tet5TqMgpQePt/nNBt+sipuA1E3BTD/dh+Ts= Received: from localhost.localdomain ( [localhost]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 03 Jun 2025 09:02:02 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 12453671181303604206 EX-QQ-RecipientCnt: 8 From: tuhaowen To: rafael@kernel.org Cc: tuhaowen@uniontech.com, huangbibo@uniontech.com, len.brown@intel.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, pavel@kernel.org, wangyuli@uniontech.com Subject: [PATCH v4] PM/console: Fix the black screen issue Date: Tue, 3 Jun 2025 09:01:57 +0800 Message-Id: <20250603010157.19121-1-tuhaowen@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20250526010854.7834-1-tuhaowen@uniontech.com> References: <20250526010854.7834-1-tuhaowen@uniontech.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: zesmtpip:uniontech.com:qybglogicsvrgz:qybglogicsvrgz8a-1 X-QQ-XMAILINFO: OFwcIyq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8HY8A= X-QQ-XMRINFO: NyFYKkN4Ny6FSmKK/uo/jdU= X-QQ-RECHKSPAM: 0 Content-Type: text/plain; charset="utf-8" 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 --- Changes in v4: - Moved `vt_switch_done =3D false;` below the `if (orig_fgconsole >=3D 0)` block to ensure it is only reset after a console switch has occurred. - Link to v3: https://lore.kernel.org/all/20250526010854.7834-1-tuhaowen@un= iontech.com - Link to v2: https://lore.kernel.org/all/20250516084011.29309-1-tuhaowen@u= niontech.com - Link to v1: https://lore.kernel.org/all/20250516034643.22355-1-tuhaowen@u= niontech.com --- 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) =20 static int orig_fgconsole, orig_kmsg; +static bool vt_switch_done; =20 static DEFINE_MUTEX(vt_switch_mutex); =20 @@ -136,17 +137,21 @@ void pm_prepare_console(void) if (orig_fgconsole < 0) return; =20 + vt_switch_done =3D true; + orig_kmsg =3D vt_kmsg_redirect(SUSPEND_CONSOLE); return; } =20 void pm_restore_console(void) { - if (!pm_vt_switch()) + if (!pm_vt_switch() && !vt_switch_done) return; =20 if (orig_fgconsole >=3D 0) { vt_move_to_console(orig_fgconsole, 0); vt_kmsg_redirect(orig_kmsg); } + + vt_switch_done =3D false; } --=20 2.20.1