From patchwork Thu Apr 30 06:42:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arseny Maslennikov X-Patchwork-Id: 214049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIM_ADSP_ALL, DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2255EC83006 for ; Thu, 30 Apr 2020 07:16:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD5A020784 for ; Thu, 30 Apr 2020 07:16:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cs.msu.ru header.i=@cs.msu.ru header.b="jK/eik5o" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726752AbgD3HQp (ORCPT ); Thu, 30 Apr 2020 03:16:45 -0400 Received: from mail.cs.msu.ru ([188.44.42.39]:50463 "EHLO mail.cs.msu.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726412AbgD3HQo (ORCPT ); Thu, 30 Apr 2020 03:16:44 -0400 X-Greylist: delayed 1989 seconds by postgrey-1.27 at vger.kernel.org; Thu, 30 Apr 2020 03:16:42 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cs.msu.ru; s=dkim; h=Subject:Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=MCF4uYzz7F8p7ezZgMR/XpDxwDlhjV1t3xDjOnjcv0g=; b=jK/eik5oO4DUBeovMYOGZQDeET +6RSThmOVSvh1cJXdCq2stRPQYcRSWUU+FoZGiNOjPee+4ndh54dFCbWc+8wie9XNZtPY0FOb+p5X GJL69YgWKZhx2e/l0uQJd3ls4AqfiFJny/Atg5CgMElvFtpIxCZGypbpHdKxL7T5v1/IOKM279gB/ TqEXLFUikP0VYfi003El6Avh/FuVZ/oLBOHy7cPFyPIVnvz1vBmPM975nFZUhAMQ5IrunOImkxoJs b9quQUZr6SkZYu6X0HPFXZuxfxqcYKcnO/N6xmVzUyxnO9NJFyWfMLoIwDocFLCIBoVz3YyyeOCjI uZxPUYew==; Received: from [37.204.119.143] (port=42272 helo=localhost.localdomain) by mail.cs.msu.ru with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93.0.4 (FreeBSD)) (envelope-from ) id 1jU2uv-000B4I-4v; Thu, 30 Apr 2020 09:43:29 +0300 From: Arseny Maslennikov To: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Arseny Maslennikov , Rob Landley , "Eric W. Biederman" , Pavel Machek , linux-api@vger.kernel.org, "Vladimir D. Seleznev" Date: Thu, 30 Apr 2020 09:42:57 +0300 Message-Id: <20200430064301.1099452-4-ar@cs.msu.ru> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200430064301.1099452-1-ar@cs.msu.ru> References: <20200430064301.1099452-1-ar@cs.msu.ru> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 37.204.119.143 X-SA-Exim-Mail-From: ar@cs.msu.ru Subject: [PATCH v3 3/7] n_tty: Send SIGINFO to fg pgrp on status request character X-SA-Exim-Version: 4.2.1 X-SA-Exim-Scanned: Yes (on mail.cs.msu.ru) Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org No kerninfo line is printed yet. No existing implementation of this on any Unix-like system echoes the status character; no existing implementation discards or flushes pending input on VSTATUS receipt. Thus we do neither. There are existing popular TUI applications (e. g. mutt) that only turn off icanon and not iexten, but still do not expect any special treatment of the status request character — so we require all three: isig, icanon and iexten to trigger this. Signed-off-by: Arseny Maslennikov --- drivers/tty/n_tty.c | 15 +++++++++++++-- include/linux/tty.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 1794d84e7..10d6b60a5 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -79,6 +79,10 @@ #define ECHO_BLOCK 256 #define ECHO_DISCARD_WATERMARK N_TTY_BUF_SIZE - (ECHO_BLOCK + 32) +#define SIG_FLUSHING_MASK ( \ + rt_sigmask(SIGINT) | rt_sigmask(SIGQUIT) | \ + rt_sigmask(SIGTSTP) ) +#define SIG_FLUSHING(sig) ((1 << sig) & SIG_FLUSHING_MASK) #undef N_TTY_TRACE #ifdef N_TTY_TRACE @@ -1122,7 +1126,7 @@ static void isig(int sig, struct tty_struct *tty) { struct n_tty_data *ldata = tty->disc_data; - if (L_NOFLSH(tty)) { + if (L_NOFLSH(tty) || (!SIG_FLUSHING(sig))) { /* signal only */ __isig(sig, tty); @@ -1244,7 +1248,8 @@ n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c) if (I_IXON(tty)) start_tty(tty); if (L_ECHO(tty)) { - echo_char(c, tty); + if (c != STATUS_CHAR(tty)) + echo_char(c, tty); commit_echoes(tty); } else process_echoes(tty); @@ -1294,6 +1299,9 @@ n_tty_receive_char_special(struct tty_struct *tty, unsigned char c) } else if (c == SUSP_CHAR(tty)) { n_tty_receive_signal_char(tty, SIGTSTP, c); return 0; + } else if (c == STATUS_CHAR(tty)) { + n_tty_receive_signal_char(tty, SIGINFO, c); + return 0; } } @@ -1848,6 +1856,9 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old) set_bit(INTR_CHAR(tty), ldata->char_map); set_bit(QUIT_CHAR(tty), ldata->char_map); set_bit(SUSP_CHAR(tty), ldata->char_map); + if (L_ICANON(tty) && L_IEXTEN(tty)) { + set_bit(STATUS_CHAR(tty), ldata->char_map); + } } clear_bit(__DISABLED_CHAR, ldata->char_map); ldata->raw = 0; diff --git a/include/linux/tty.h b/include/linux/tty.h index bd5fe0e90..8411fd18d 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -120,6 +120,7 @@ struct tty_bufhead { #define WERASE_CHAR(tty) ((tty)->termios.c_cc[VWERASE]) #define LNEXT_CHAR(tty) ((tty)->termios.c_cc[VLNEXT]) #define EOL2_CHAR(tty) ((tty)->termios.c_cc[VEOL2]) +#define STATUS_CHAR(tty) ((tty)->termios.c_cc[VSTATUS]) #define _I_FLAG(tty, f) ((tty)->termios.c_iflag & (f)) #define _O_FLAG(tty, f) ((tty)->termios.c_oflag & (f)) From patchwork Thu Apr 30 06:42:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arseny Maslennikov X-Patchwork-Id: 214047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIM_ADSP_ALL, DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75171C83001 for ; Thu, 30 Apr 2020 07:17:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46A6120838 for ; Thu, 30 Apr 2020 07:17:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cs.msu.ru header.i=@cs.msu.ru header.b="tYImIuIy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726951AbgD3HRQ (ORCPT ); Thu, 30 Apr 2020 03:17:16 -0400 Received: from mail.cs.msu.ru ([188.44.42.39]:50590 "EHLO mail.cs.msu.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726924AbgD3HRP (ORCPT ); Thu, 30 Apr 2020 03:17:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cs.msu.ru; s=dkim; h=Subject:Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Yx55Thu7Gf0r0u/XFEjGbPEa2L3yF6iBFpJzZun4g9A=; b=tYImIuIyPJagcc6FPVaOYZLQPi 9kAFEOVgxEnOigCDvy0mExWX2v805sfZGc3kJK6SoxL/pCzdzOCAWkvnDv3KIPDHfo/lhJ6FhxaET DrHyMSPlI4YTxZ8axbx0GIo+OfL6Gvh73ZhFBXVyQe3VQTLG8omAv8GZlQJuu6kV5fHYgGcNUoYGT 4/ZsebLY3y2pzbgYa6zzQhtuLClMntI4B0vcOeXBWFsIy8uiaB60HLTpviorkpr2Z/GvBWc1soULz gBp4z5DQh6jUGBETpVMYRmlin6sKajWSVq7B5AI4a8tDLUDTnA9OzvMX43561gzaHV5c/rQlLvSsT nensbArw==; Received: from [37.204.119.143] (port=42272 helo=localhost.localdomain) by mail.cs.msu.ru with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93.0.4 (FreeBSD)) (envelope-from ) id 1jU2uv-000B4I-Do; Thu, 30 Apr 2020 09:43:29 +0300 From: Arseny Maslennikov To: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Arseny Maslennikov , Rob Landley , "Eric W. Biederman" , Pavel Machek , linux-api@vger.kernel.org, "Vladimir D. Seleznev" Date: Thu, 30 Apr 2020 09:42:58 +0300 Message-Id: <20200430064301.1099452-5-ar@cs.msu.ru> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200430064301.1099452-1-ar@cs.msu.ru> References: <20200430064301.1099452-1-ar@cs.msu.ru> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 37.204.119.143 X-SA-Exim-Mail-From: ar@cs.msu.ru Subject: [PATCH v3 4/7] linux/signal.h: Ignore SIGINFO by default in new tasks X-SA-Exim-Version: 4.2.1 X-SA-Exim-Scanned: Yes (on mail.cs.msu.ru) Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org This matches the behaviour of other Unix-like systems that have SIGINFO and causes less harm to processes that do not install handlers for this signal, making the keyboard status character non-fatal for them. This is implemented with the assumption that SIGINFO is defined to be equivalent to SIGPWR; still, there is no reason for PWR to result in termination of the signal recipient anyway — it does not indicate there is a fatal problem with the recipient's execution context (like e.g. FPE/ILL do), and we have TERM/KILL for explicit termination requests. To put it another way: The only scenario where system behaviour actually changes is when the signal recipient has default disposition for SIGPWR. If a process chose to interpret a SIGPWR as an incentive to cleanly terminate, it would supply its own handler — and this commit does not affect processes with non-default handlers. Signed-off-by: Arseny Maslennikov --- include/linux/signal.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/linux/signal.h b/include/linux/signal.h index 05bacd2ab..dc31da8fc 100644 --- a/include/linux/signal.h +++ b/include/linux/signal.h @@ -369,7 +369,7 @@ extern bool unhandled_signal(struct task_struct *tsk, int sig); * | SIGSYS/SIGUNUSED | coredump | * | SIGSTKFLT | terminate | * | SIGWINCH | ignore | - * | SIGPWR | terminate | + * | SIGPWR | ignore | * | SIGRTMIN-SIGRTMAX | terminate | * +--------------------+------------------+ * | non-POSIX signal | default action | @@ -420,7 +420,8 @@ extern bool unhandled_signal(struct task_struct *tsk, int sig); #define SIG_KERNEL_IGNORE_MASK (\ rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \ - rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) ) + rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) | \ + rt_sigmask(SIGINFO) ) #define SIG_SPECIFIC_SICODES_MASK (\ rt_sigmask(SIGILL) | rt_sigmask(SIGFPE) | \ From patchwork Thu Apr 30 06:43:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseny Maslennikov X-Patchwork-Id: 214046 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIM_ADSP_ALL, DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1338C83002 for ; Thu, 30 Apr 2020 07:17:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5972214D8 for ; Thu, 30 Apr 2020 07:17:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cs.msu.ru header.i=@cs.msu.ru header.b="Q4rrgDV0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726937AbgD3HRP (ORCPT ); Thu, 30 Apr 2020 03:17:15 -0400 Received: from mail.cs.msu.ru ([188.44.42.39]:50583 "EHLO mail.cs.msu.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726891AbgD3HRL (ORCPT ); Thu, 30 Apr 2020 03:17:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cs.msu.ru; s=dkim; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=8X7J2PrsdtBE1Q+hOf7I5rfSDP6MpQUyNWTcjJ6lkk0=; b=Q4rrgDV0cUMIfVpQ5JAenDdsEi f9ERFOsGa07CblhpOLgtLmfOrNVVB7O4E6wN0uWyq3kBW2pPJxu27UoaqU4NRD7eItyUaEJQ8Dgfs HVcQPQ8vReJcAiz5aT+7xSREngBq9DdKth8jupoC7UX0a0dohKyT9tkD/pPOHgOqnrAm0TKdO02iW LoSBjo8xozaRmh6ttMTW1NOz3TuRIAm2Qg2iOB1r0CWuPVxgxO9OpyRfj8c/kWdPzxtuB6rOF325G eys1uF4Q0DIwya+xWFw3LEdAhclgKX3KuOayqXVUBR3aS/rIJK5yZGEhYFt3V701XnL8oHxbyYSuW 08RRhM/A==; Received: from [37.204.119.143] (port=42272 helo=localhost.localdomain) by mail.cs.msu.ru with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93.0.4 (FreeBSD)) (envelope-from ) id 1jU2uw-000B4I-0u; Thu, 30 Apr 2020 09:43:30 +0300 From: Arseny Maslennikov To: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Arseny Maslennikov , Rob Landley , "Eric W. Biederman" , Pavel Machek , linux-api@vger.kernel.org, "Vladimir D. Seleznev" Date: Thu, 30 Apr 2020 09:43:00 +0300 Message-Id: <20200430064301.1099452-7-ar@cs.msu.ru> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200430064301.1099452-1-ar@cs.msu.ru> References: <20200430064301.1099452-1-ar@cs.msu.ru> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 37.204.119.143 X-SA-Exim-Mail-From: ar@cs.msu.ru Subject: [PATCH v3 6/7] n_tty: ->ops->write: Cut core logic out to a separate function X-SA-Exim-Version: 4.2.1 X-SA-Exim-Scanned: Yes (on mail.cs.msu.ru) Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org To simplify internal re-use of the line discipline's write method, we isolate the work it does to its own function. Since in-kernel callers might not refer to the tty through a file, the struct file* argument might make no sense, so we also stop tty_io_nonblock() from dereferencing file too early, allowing to pass NULL as the referring file here. Signed-off-by: Arseny Maslennikov --- drivers/tty/n_tty.c | 33 ++++++++++++++++++++++----------- include/linux/tty.h | 2 +- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 10d6b60a5..f72a3fd4b 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -2309,22 +2309,15 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, * lock themselves) */ -static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, - const unsigned char *buf, size_t nr) +static ssize_t do_n_tty_write(struct tty_struct *tty, struct file *file, + const unsigned char *buf, size_t nr) { const unsigned char *b = buf; DEFINE_WAIT_FUNC(wait, woken_wake_function); int c; ssize_t retval = 0; - /* Job control check -- must be done at start (POSIX.1 7.1.1.4). */ - if (L_TOSTOP(tty) && file->f_op->write != redirected_tty_write) { - retval = tty_check_change(tty); - if (retval) - return retval; - } - - down_read(&tty->termios_rwsem); + lockdep_assert_held_read(&tty->termios_rwsem); /* Write out any echoed characters that are still pending */ process_echoes(tty); @@ -2392,10 +2385,28 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, remove_wait_queue(&tty->write_wait, &wait); if (nr && tty->fasync) set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); - up_read(&tty->termios_rwsem); return (b - buf) ? b - buf : retval; } +static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, + const unsigned char *buf, size_t nr) +{ + ssize_t retval = 0; + + /* Job control check -- must be done at start (POSIX.1 7.1.1.4). */ + if (L_TOSTOP(tty) && file->f_op->write != redirected_tty_write) { + retval = tty_check_change(tty); + if (retval) + return retval; + } + + down_read(&tty->termios_rwsem); + retval = do_n_tty_write(tty, file, buf, nr); + up_read(&tty->termios_rwsem); + + return retval; +} + /** * n_tty_poll - poll method for N_TTY * @tty: terminal device diff --git a/include/linux/tty.h b/include/linux/tty.h index cafb9b7f7..3499845ab 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -390,7 +390,7 @@ static inline void tty_set_flow_change(struct tty_struct *tty, int val) static inline bool tty_io_nonblock(struct tty_struct *tty, struct file *file) { - return file->f_flags & O_NONBLOCK || + return (file && file->f_flags & O_NONBLOCK) || test_bit(TTY_LDISC_CHANGING, &tty->flags); }