Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp671770ybl; Tue, 28 Jan 2020 09:51:51 -0800 (PST) X-Google-Smtp-Source: APXvYqwfrOSsAiBVYSQgx/QR50CDcpA7MRv0k9wCX/TxbgeYgSO6hn4k7BmtvPEzFmLPWe3+KpfU X-Received: by 2002:aca:530e:: with SMTP id h14mr3549011oib.105.1580233911617; Tue, 28 Jan 2020 09:51:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580233911; cv=none; d=google.com; s=arc-20160816; b=j4SH8Qd5Rmyc6EY74F5DVuFHRAiAMAUIMwE8lbo2L/HhQzh195yi5ZgKlCKAJgdvG4 k594/JaZLM0JFqRYbfx/Sp1JqMRYSYsX1lcaiNHIHbiwZjNE4LyMR6Qi+YmkC4u32hGM IcRC2skUuUnmc/x4Xz/iWR9Bjcpm1RoKv2IpGrjVqfS9dQ9X9KBSx/EEXz+VRvV2pVVu TQF9vCXd+xyYnIP7/v2mFNujGWjAW+5fSqf34Xmzb3r6lbv3O0OfC7rP9Tp6BUlDUtrg DH7/UUQK+xR15FIQV8xZCErwmaqJM9rx0Agn0IZLLB5E2YbmfKagAiQq32KIRVLCv6U2 Ngww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature:dkim-signature; bh=gwBbxsSJOIvt83aWb96sgd8VWiHVKGPyLBDy39Olyhg=; b=0u/9T8xH7iGL3jZrqBuR0Kr8xFBQSHF5vsV+rmfla4c91aYyetNywcZ+TL1H/HwSHG P9uSKyPkcCkkJHVZHGAYDlJdwg/s5k3m7ko7J8iVU0FeVjtZkU7xUfHMb8Xua6nbEQBH Y5llJy4Uql18mJIfVIVosrhIiaYI388GP1Ug+bpzPlIn2Bin1IApNE4GmaQwXw17gksC ErLD4Osj94x5rY3wXNiB4hTAqUZ9A0HM9i9JmzmX20g5mYRDjGR8eyJHCtAOV2M1Pnqz sX4lIWbnf4RcAuNfg1sJ49RDYENuWqultvqbZE0o2N4BMkhXQ0wHd4Uh/m8R0TU32QG0 YrGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pobox.com header.s=sasl header.b=f+NYoWYr; dkim=temperror (no key for signature) header.i=@fluxnic.net header.s=2016-12.pbsmtp header.b=HeAZfQya; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n18si9845762otf.285.2020.01.28.09.51.39; Tue, 28 Jan 2020 09:51:51 -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=@pobox.com header.s=sasl header.b=f+NYoWYr; dkim=temperror (no key for signature) header.i=@fluxnic.net header.s=2016-12.pbsmtp header.b=HeAZfQya; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726318AbgA1Rup (ORCPT + 99 others); Tue, 28 Jan 2020 12:50:45 -0500 Received: from pb-smtp20.pobox.com ([173.228.157.52]:51111 "EHLO pb-smtp20.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726066AbgA1Rup (ORCPT ); Tue, 28 Jan 2020 12:50:45 -0500 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 4B8D3AF71F; Tue, 28 Jan 2020 12:50:43 -0500 (EST) (envelope-from nico@fluxnic.net) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=date:from:to :cc:subject:message-id:mime-version:content-type; s=sasl; bh=Q+/ 6TsAi07c3WjpX7xvEfYiz/p0=; b=f+NYoWYrsNIzBLhr2MWYMAxkJ1qbDaozCJD QmrUBOzYkBfTaAgaITbdmApZ6g76+pALRKuaHazXuIpVWbAw23PIuMRYBasFySdg yeLWxtdoAjg4LueTDVj98VEjJF7izQEI2icP+w4srmTnFD9cLpw2rCLs/0RAiDD7 95aeZVUI= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 436F2AF71E; Tue, 28 Jan 2020 12:50:43 -0500 (EST) (envelope-from nico@fluxnic.net) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=fluxnic.net; h=date:from:to:cc:subject:message-id:mime-version:content-type; s=2016-12.pbsmtp; bh=QSzYoKchC8bAVwKEjJbgLQFSIOW5hbn3tY7WNGl53+0=; b=HeAZfQyauHikkz/pJy1a6oiqIOAmugWNSQNj04kpw13XJZw3nxkhBmxj8r1MQ5zlhBu+TA8ZLeE30MmbwG8KCTMW/cY2Ov5AZD9VbKE6i4MTmpY83eMCg+2gmVVlioIT1lKZNQksTQ2lEtGYfc3BswhtZLrL/O6vfKiNK7dc5iI= Received: from yoda.home (unknown [24.203.50.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 3B531AF71D; Tue, 28 Jan 2020 12:50:40 -0500 (EST) (envelope-from nico@fluxnic.net) Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTPSA id 5DADC2DA00E3; Tue, 28 Jan 2020 12:50:38 -0500 (EST) Date: Tue, 28 Jan 2020 12:50:33 -0500 (EST) From: Nicolas Pitre To: Greg Kroah-Hartman cc: Lukas Wunner , linux-kernel@vger.kernel.org Subject: [PATCH] vt: fix scrollback flushing on background consoles Message-ID: User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Pobox-Relay-ID: B29C772E-41F6-11EA-9629-B0405B776F7B-78420484!pb-smtp20.pobox.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit a6dbe4427559 ("vt: perform safe console erase in the right order") provided fixes to an earlier commit by gathering all console scrollback flushing operations in a function of its own. This includes the invocation of vc_sw->con_switch() as previously done through a update_screen() call. That commit failed to carry over the con_is_visible() conditional though, as well as cursor handling, which caused problems when "\e[3J" was written to a background console. One could argue for preserving the call to update_screen(). However this does far more than we need, and it is best to remove scrollback assumptions from it. Instead let's gather the minimum needed to actually perform scrollback flushing properly in that one place. While at it, let's document the vc_sw->con_switch() side effect being relied upon. Signed-off-by: Nicolas Pitre Reported-and-tested-by: Lukas Wunner Cc: stable@vger.kernel.org diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 34aa39d1ae..3b4ccc2a30 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -936,10 +936,21 @@ static void flush_scrollback(struct vc_data *vc) WARN_CONSOLE_UNLOCKED(); set_origin(vc); - if (vc->vc_sw->con_flush_scrollback) + if (vc->vc_sw->con_flush_scrollback) { vc->vc_sw->con_flush_scrollback(vc); - else + } else if (con_is_visible(vc)) { + /* + * When no con_flush_scrollback method is provided then the + * legacy way for flushing the scrollback buffer is to use + * a side effect of the con_switch method. We do it only on + * the foreground console as background consoles have no + * scrollback buffers in that case and we obviously don't + * want to switch to them. + */ + hide_cursor(vc); vc->vc_sw->con_switch(vc); + set_cursor(vc); + } } /*