From nobody Sat Oct 11 08:30:55 2025 Received: from smtpbgeu2.qq.com (smtpbgeu2.qq.com [18.194.254.142]) (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 3377E1A28D; Wed, 11 Jun 2025 03:24:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.194.254.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749612285; cv=none; b=WcoQToMUN+kGxLLNgyjahRZ71MYSK93Sx0kgiG0EidLKIHwvDZ4BupvcPgvMPguZTU9wnjOFl3ZhTEm2kvyT9j1BldEbF8IVRbnWtbTWmYcvkQZ/MJdS1NziHKi7llg9LWqNF7OvJ5UryK65kkQMEAv2/jxJZq0Qy1hSy0jG0sY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749612285; c=relaxed/simple; bh=fyPQ/mfs2CSaeT6RM8/3j9A3OgCvFV5ebkXfbNQ6tqA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YHLQ4iUhwffyIN5l1gFM5kJFsYzUliawbWgGyKO08tk5O6EcLBHrgg/5CUfqT/FzlWSl6QNZ2Ty+fG2ze2VyLPwKjofFGyeGXDj6LY0D2zpyr/RoanHWJdrM3sBGA5eNSAWjcTV4MShkF3w1613KUZR8+E1C4xvc+fNBjRKy0Po= 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=PwqdEJBU; arc=none smtp.client-ip=18.194.254.142 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="PwqdEJBU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1749612238; bh=A93XqZVqVhYz+KFT6k3LBe2oQch3w3UxJ0GXN9kjeh4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=PwqdEJBU58xv2fN/GyFrVsY4q+yUzchYh1yQdyDbOkzOLW+gsmutc3EKCPmPRdo1M rK9l0TyIXN5xEF9I6iJ/vDFyQzvjEpBYWe8ugLfcU5ZI4aPiazt/TPy5NMd9iWF/oQ LTfN3b4KY2nM40MFZ1WGknFJvuhlDwUT8ZVFE51I= X-QQ-mid: zesmtpip3t1749612231t9eb799bf X-QQ-Originating-IP: zvO0QNl2WUmxFIua18O1d7WBy41GUoKiP/HGHAcVAK0= Received: from localhost.localdomain ( [localhost]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 11 Jun 2025 11:23:49 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 12403305686698106879 EX-QQ-RecipientCnt: 8 From: tuhaowen To: pavel@kernel.org, rafael@kernel.org, linux-pm@vger.kernel.org Cc: tuhaowen@uniontech.com, huangbibo@uniontech.com, len.brown@intel.com, linux-kernel@vger.kernel.org, wangyuli@uniontech.com Subject: [PATCH v4 RESEND] PM/console: Fix the black screen issue Date: Wed, 11 Jun 2025 11:23:45 +0800 Message-Id: <20250611032345.29962-1-tuhaowen@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20250603010157.19121-1-tuhaowen@uniontech.com> References: <20250603010157.19121-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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+VbEyxrrU/jiwlX+cTM= 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