From patchwork Wed Jan 9 03:55:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 155048 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp260800jaa; Tue, 8 Jan 2019 20:04:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN5bS8yNsEj3N1i4Xbz1r1OqvmYH2xSlnAuKBCji0bivO8IcybcX7wr2Siym4uExFmw/60Ue X-Received: by 2002:a17:902:22f:: with SMTP id 44mr4433252plc.137.1547006678698; Tue, 08 Jan 2019 20:04:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547006678; cv=none; d=google.com; s=arc-20160816; b=TEZjTQzZgRiXLtxHXg60AVz1+pk5n6DLT1G3bFwIRoKenJNbTPSKmn7rj055e6eh79 YKbOFSEqyN431MyhaF1rk2XhdpAKcCfRqqltp0x5TUp79i8WLZwzKxp+z1wLy4arfX58 y4hq4zj8tfKu5q7U51f5uNCr65AaF9NiYYqnVkQQVwSayC3PFt4pipgUbxJJkvDhiyKC yXgzgIuynvttZfGXN6HkndvZN9fz97OgskhG08KCpJInMEc3alVHWZNfR5jfC4zTta/x i9RjVWkeBpAprx5GdEC2yNhuG9zDYz6xeEnhHvxY44bVphSfsqYoKxNQ/xandYCDxf6E 1fXQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RiDIhn3k+y3rCrALgB+0GpXM6fBO8JgdX0ogmxvYqgQ=; b=BjRUgljcSEL5NkxwLxeWXcNQaVPhnxYL2bUZBs7DznvkrNbSzp1epoHYsWuJZdFI6X +SK2rV0gLjfZc6YuwR9RnOH9ciMnHVTglLJ023+1VwueTctxiHCrJ5YHBfddEyc+m01U kjMFRbwogvj44INZ36cmmjRz1fmccg2WGZcN7ROiuNPYP7W75IwaxP2+oE1l28gNQeyo r7vI3OzJAO3tBbUG5Dn44xuwPT/Gr+8UmVNUku74YTM67obXKvvFsdJfXVBO0RBAXRAq rmg7gEZ1dIPCfHExLf23+WhdaGSSY4BYp++9MOxlDChrHILzS05TKEyLjqJvNiQOD0sO /DDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pobox.com header.s=sasl header.b=jlzCwbui; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si66252484pgj.34.2019.01.08.20.04.38; Tue, 08 Jan 2019 20:04:38 -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=jlzCwbui; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729389AbfAIEEh (ORCPT + 31 others); Tue, 8 Jan 2019 23:04:37 -0500 Received: from pb-smtp20.pobox.com ([173.228.157.52]:59851 "EHLO pb-smtp20.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727828AbfAIEEh (ORCPT ); Tue, 8 Jan 2019 23:04:37 -0500 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 099F65C4AA; Tue, 8 Jan 2019 22:55:51 -0500 (EST) (envelope-from nicolas.pitre@linaro.org) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=/oWaIbI7kf1YpW02K4Zc5hquC hM=; b=jlzCwbui5GC/9wY/IYIIaT8RSrLknPxqW424qnBcWwTdOVN1DeG/z7c+U c7lI6Tuoy+NeREdbbGJDG3oscKBfhK2jgN2jXXQ6dluJAOqwGjApz2dRncTrgvwv yFSPMGUHoAYBkm7xepAo+bSt7DpOP369dfSGxLIBcqOaVKG82Q= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 03CC85C4A9; Tue, 8 Jan 2019 22:55:51 -0500 (EST) (envelope-from nicolas.pitre@linaro.org) Received: from yoda.home (unknown [70.82.104.228]) (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 1D93D5C4A8; Tue, 8 Jan 2019 22:55:48 -0500 (EST) (envelope-from nicolas.pitre@linaro.org) Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id CD8FB2DA06F2; Tue, 8 Jan 2019 22:55:45 -0500 (EST) From: Nicolas Pitre To: Greg Kroah-Hartman Cc: Dave Mielke , linux-kernel@vger.kernel.org Subject: [PATCH 5/6] vcs: poll(): cope with a deallocated vt Date: Tue, 8 Jan 2019 22:55:03 -0500 Message-Id: <20190109035504.8413-6-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190109035504.8413-1-nicolas.pitre@linaro.org> References: <20190109035504.8413-1-nicolas.pitre@linaro.org> MIME-Version: 1.0 X-Pobox-Relay-ID: 72C0E60C-13C2-11E9-9222-D889C09F693B-78420484!pb-smtp20.pobox.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When VT_DISALLOCATE is used on a vt, user space waiting with poll() on the corresponding /dev/vcs device is not awakened. This is now fixed by returning POLLHUP|POLLERR to user space. Also, in the normal screen update case, we don't set POLLERR anymore as POLLPRI alone is a much more logical response in a non-error situation, saving some confusion on the user space side. The only known user app making use of poll() on /dev/vcs* is BRLTTY which is known to cope with that change already, so the risk of breakage is pretty much nonexistent. Signed-off-by: Nicolas Pitre --- drivers/tty/vt/vc_screen.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) -- 2.20.1 diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c index 3dba60825c..1bbe2a30cd 100644 --- a/drivers/tty/vt/vc_screen.c +++ b/drivers/tty/vt/vc_screen.c @@ -80,7 +80,7 @@ struct vcs_poll_data { struct notifier_block notifier; unsigned int cons_num; - bool seen_last_update; + int event; wait_queue_head_t waitq; struct fasync_struct *fasync; }; @@ -94,7 +94,7 @@ vcs_notifier(struct notifier_block *nb, unsigned long code, void *_param) container_of(nb, struct vcs_poll_data, notifier); int currcons = poll->cons_num; - if (code != VT_UPDATE) + if (code != VT_UPDATE && code != VT_DEALLOCATE) return NOTIFY_DONE; if (currcons == 0) @@ -104,7 +104,7 @@ vcs_notifier(struct notifier_block *nb, unsigned long code, void *_param) if (currcons != vc->vc_num) return NOTIFY_DONE; - poll->seen_last_update = false; + poll->event = code; wake_up_interruptible(&poll->waitq); kill_fasync(&poll->fasync, SIGIO, POLL_IN); return NOTIFY_OK; @@ -261,7 +261,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) poll = file->private_data; if (count && poll) - poll->seen_last_update = true; + poll->event = 0; read = 0; ret = 0; while (count) { @@ -616,12 +616,21 @@ static __poll_t vcs_poll(struct file *file, poll_table *wait) { struct vcs_poll_data *poll = vcs_poll_data_get(file); - __poll_t ret = DEFAULT_POLLMASK|EPOLLERR|EPOLLPRI; + __poll_t ret = DEFAULT_POLLMASK|EPOLLERR; if (poll) { poll_wait(file, &poll->waitq, wait); - if (poll->seen_last_update) + switch (poll->event) { + case VT_UPDATE: + ret = DEFAULT_POLLMASK|EPOLLPRI; + break; + case VT_DEALLOCATE: + ret = DEFAULT_POLLMASK|EPOLLHUP|EPOLLERR; + break; + case 0: ret = DEFAULT_POLLMASK; + break; + } } return ret; }