Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4663508imc; Mon, 25 Feb 2019 08:46:03 -0800 (PST) X-Google-Smtp-Source: AHgI3IZSIigiNtE6Wc6pQNIzp/Zrqepg57djVRVO/0l9XYwLFyy7cRcaojFMwizIwaWXxYmhAX7O X-Received: by 2002:a63:fb42:: with SMTP id w2mr20112008pgj.408.1551113163691; Mon, 25 Feb 2019 08:46:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551113163; cv=none; d=google.com; s=arc-20160816; b=AzsNISlb2xBXxrS6i1GQgef/JGlZPRA3bmpEF15KbmR3+WIQOcMLXnkxm3pIB/IntT zLtJDgrDfVxRtYGFiLDQ19v3B3mvzdCP0LX78f2i+IOQKDFtYcXREm4h6q9M3KDm0ovs LPvHxaX0133yASc3zKzehCa3IlvC52L+/d0Z2kvmEa/ZCX178YZcw2/guFBHTjWOlAWj ySZQlRBK9shGhdXgDYwf2UBl808P3IWatZmcjnneQ4a9m1buYZkE2pSEa67Bb/cwSayI eCJTL6xdzrOq2wZCdU4A9MLOySY1po+6T9Vff6y4IcSVD1p9c4/MlSRW1FK7ktlElSMA 8nLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=cf+xSHoB43MOKYD9fyViYocjeK66Ah4m1du0dM8o9+o=; b=Jh6xrde1LYk9F4ezdoCPjwEbvZ+BAP9K4xa7q8JRp0UUyBvR5aGc14Od6hibdvwAeJ uaHdvWEgH3G1UGs6N4N7pzH6/YJQAfdZ8Z5OUHe62nhPqlAKABmgVtUkMDGZpwAgKonG BHO5+PhM+rnU6p0aLvvXtU+oAqXa7q11VdtJ+8NbKDjA+WRzi9ePwykEdhXf68xaYIrQ 1WZugmeUFytJKI+3jPTdc7L17xEkucdbfMUO6XI68eQGZDvTA/8AEEDQ41fuxN0sihDG 3jxHTFj7zk+Ls7QrII7Y9nXVkEinPtptVZ6jWh5+SqL6iOOPctuX57++38wJlgfqGf+X kRRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tomli.me header.s=1490979754 header.b=ciQjUELq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tomli.me Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b17si9636281pls.181.2019.02.25.08.45.48; Mon, 25 Feb 2019 08:46:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@tomli.me header.s=1490979754 header.b=ciQjUELq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tomli.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728379AbfBYQoF (ORCPT + 99 others); Mon, 25 Feb 2019 11:44:05 -0500 Received: from tomli.me ([153.92.126.73]:38580 "EHLO tomli.me" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728138AbfBYQoF (ORCPT ); Mon, 25 Feb 2019 11:44:05 -0500 Received: from tomli.me (localhost [127.0.0.1]) by tomli.me (OpenSMTPD) with ESMTP id fe172d3d; Mon, 25 Feb 2019 16:44:02 +0000 (UTC) X-HELO: localhost.lan Authentication-Results: tomli.me; auth=pass (login) smtp.auth=tomli Received: from Unknown (HELO localhost.lan) (2402:f000:1:1501:200:5efe:3d30:359c) by tomli.me (qpsmtpd/0.95) with ESMTPSA (DHE-RSA-CHACHA20-POLY1305 encrypted); Mon, 25 Feb 2019 16:44:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=tomli.me; h=from:to:cc:subject:date:message-id:mime-version:content-transfer-encoding; s=1490979754; bh=t/bB+YE5fPUbLxlwyf3lZ49YrKiMqhxAqMwXLYGtHZo=; b=ciQjUELqnBgHlmgOv7sjb0FLgu+mj6CYhSJZYoOssx17IiNyHCBg/e+uRlT4a9JslYq0rvTYmbLYY40lbFreTqHHVkNbFeBVfCPITn5KPw1eRzYDhy5kK7arChjDtnYqjzIZzfeCX+A1pdrKci1KMYAeY98HOhWlo9dLfNiqNRFkd58actvpv8NipS4Zz2NI5mzWa975kRASfyP0nFwopgdOxeUCbI1zIQOKvCY/3dhHRmjeR2IjAXKpBKe8ubXlzTKGHnGzV4F8cB48cPcVQk9a7gcZ3zfqMEVmqErgoZFJsrPUQQ3Xb37wLaDJxQQJOwbHd3nvH7CRQPXYMS2M2g== From: Yifeng Li To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Nicolas Pitre , Adam Borowski , Mikulas Patocka , Alexander Potapenko , Yifeng Li , Mike Frysinger , Daniel Vetter Subject: [RFC 0/1] Fix TIOCL_BLANKSCREEN VT console blanking if blankinterval == 0 Date: Tue, 26 Feb 2019 00:43:45 +0800 Message-Id: <20190225164346.1359-1-tomli@tomli.me> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Previously, in the userspace, it was possible to use the "setterm" command from util-linux to blank the VT console by default, using the following command. # setterm -blank force According to the man page, > The force option keeps the screen blank even if a key is pressed. It was implemented by calling TIOCL_BLANKSCREEN. case BLANKSCREEN: ioctlarg = TIOCL_BLANKSCREEN; if (ioctl(STDIN_FILENO, TIOCLINUX, &ioctlarg)) warn(_("cannot force blank")); break; However, after Linux 4.12, this command ceased to work anymore, which is unexpected. By inspecting the kernel source, it shows that the issue was triggered by the side-effect from commit a4199f5e ("tty: Disable default console blanking interval"). The console blanking is implemented by function do_blank_screen(). It can be called by the inactive timer "console_timer" with the time specified by "blankinterval", or by the IOCTL call TIOCL_BLANKSCREEN. The variable "blank_state" is used to indicate the current status of console blanking, it can have three possible values, blank_off, blank_normal_wait, or blank_vesa_wait. When do_blank_screen() is called by "console_timer" or TIOCL_BLANKSCREEN: 1. If blank_state == vesa_off_interval, it means the console was already soft-blanked previously, and now it's the time to use VESA to put the CRT into a deeper sleep mode. When we're done, blank_state is set to blank_off, means the screen is now off, return. 2. If blank_state == blank_normal_wait, it means the console was previously on, waiting to be blanked by the inactive timer. It will set blank_state to "blank_off", means the screen is now off, and it then blanks the console. The exception is that, it also checks if VESA powersaving is on, if so, blank_state will be set to "blank_vesa_wait" instead, and the timer "console_timer" is reinitialized to call do_blank_screen() again after "vesa_off_interval", for VESA blanking, see Step 1. 3. If blank_state != blank_normal_wait at this point, it means the screen is neither on, or VESA blanked - it must be blanked already, so return. The problem is, "blank_state" will be initialized to "blank_normal_wait" in con_init(), if AND ONLY IF ("blankinterval" > 0). If "blankinterval" is 0, "blank_state" will be "blank_off" (== 0), and a call to do_blank_screen() will always abort, per Step 3. Even if a forced blanking is required from the user by calling TIOCL_BLANKSCREEN, the console won't be blanked. In other words, the screen cannot be blanked if autoblanking is disabled, unless we set a "blankinterval" beforehand, and the confusingly, the ioctl will not even return an error code. This behavior is unexpected from a user's point-of-view, since it's not mentioned in any documentation. The setterm man page suggests it will always work, and the kernel comments in uapi/linux/tiocl.h says > #define TIOCL_BLANKSCREEN 14 /* keep screen blank even if a key is pressed */ The absence of an error is also misleading. Personally, I consider it is either: (a) a bug of the implementation, "blankinterval" shouldn't be a kill switch for manual console blanking, (b) or a bug of inadequate documentation. In the following patch, I suggest making a minor change to the console blanking logic. We introduce a 4th "blank_state" - "blank_normal_notimer", it indicates the console can be blanked, but not automatically by a timer. Then, we made a change to "con_init()" - if (blankinterval == 0), "blank_state" will be set to "blank_normal_notimer" (we have similar changes to "do_unblank_screen()" and "poke_blanked_console()"). Finally, we change Step 3 in do_blank_screen() - now it will return if "blank_state" is neither "blank_normal_wait" nor "blank_normal_notimer", thus allowing the console to be blanked even if there's no timed autoblanking. Dear maintainers, please review if my proposed chance is appropriate. Thanks, Tom Li Yifeng Li (1): tty: vt.c: Fix TIOCL_BLANKSCREEN VT console blanking if blankinterval == 0 drivers/tty/vt/vt.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) -- 2.20.1