From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Beat Bolli <bbolli@ewanet.ch>,
Pavel Roskin <proski@gnu.org>, David Sterba <dsterba@suse.cz>,
Grant Edwards <grant.b.edwards@gmail.com>,
Stanislaw Gruszka <sgruszka@redhat.com>,
Hal Murray <murray+fedora@ip-64-139-1-69.sjc.megapath.net>,
Peter Hurley <peter@hurleysoftware.com>,
Alan Cox <alan@linux.intel.com>
Subject: [PATCH 3.14 13/33] tty: Fix low_latency BUG
Date: Thu, 24 Apr 2014 14:48:26 -0700 [thread overview]
Message-ID: <20140424214451.485776143@linuxfoundation.org> (raw)
In-Reply-To: <20140424214449.423169713@linuxfoundation.org>
3.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Hurley <peter@hurleysoftware.com>
commit a9c3f68f3cd8d55f809fbdb0c138ed061ea1bd25 upstream.
The user-settable knob, low_latency, has been the source of
several BUG reports which stem from flush_to_ldisc() running
in interrupt context. Since 3.12, which added several sleeping
locks (termios_rwsem and buf->lock) to the input processing path,
the frequency of these BUG reports has increased.
Note that changes in 3.12 did not introduce this regression;
sleeping locks were first added to the input processing path
with the removal of the BKL from N_TTY in commit
a88a69c91256418c5907c2f1f8a0ec0a36f9e6cc,
'n_tty: Fix loss of echoed characters and remove bkl from n_tty'
and later in commit 38db89799bdf11625a831c5af33938dcb11908b6,
'tty: throttling race fix'. Since those changes, executing
flush_to_ldisc() in interrupt_context (ie, low_latency set), is unsafe.
However, since most devices do not validate if the low_latency
setting is appropriate for the context (process or interrupt) in
which they receive data, some reports are due to misconfiguration.
Further, serial dma devices for which dma fails, resort to
interrupt receiving as a backup without resetting low_latency.
Historically, low_latency was used to force wake-up the reading
process rather than wait for the next scheduler tick. The
effect was to trim multiple milliseconds of latency from
when the process would receive new data.
Recent tests [1] have shown that the reading process now receives
data with only 10's of microseconds latency without low_latency set.
Remove the low_latency rx steering from tty_flip_buffer_push();
however, leave the knob as an optional hint to drivers that can
tune their rx fifos and such like. Cleanup stale code comments
regarding low_latency.
[1] https://lkml.org/lkml/2014/2/20/434
"Yay.. thats an annoying historical pain in the butt gone."
-- Alan Cox
Reported-by: Beat Bolli <bbolli@ewanet.ch>
Reported-by: Pavel Roskin <proski@gnu.org>
Acked-by: David Sterba <dsterba@suse.cz>
Cc: Grant Edwards <grant.b.edwards@gmail.com>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Hal Murray <murray+fedora@ip-64-139-1-69.sjc.megapath.net>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/tty/ipwireless/tty.c | 3 ---
drivers/tty/tty_buffer.c | 20 ++++----------------
drivers/usb/gadget/u_serial.c | 4 ++--
include/linux/tty.h | 2 +-
4 files changed, 7 insertions(+), 22 deletions(-)
--- a/drivers/tty/ipwireless/tty.c
+++ b/drivers/tty/ipwireless/tty.c
@@ -176,9 +176,6 @@ void ipwireless_tty_received(struct ipw_
": %d chars not inserted to flip buffer!\n",
length - work);
- /*
- * This may sleep if ->low_latency is set
- */
if (work)
tty_flip_buffer_push(&tty->port);
}
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -351,14 +351,11 @@ EXPORT_SYMBOL(tty_insert_flip_string_fla
* Takes any pending buffers and transfers their ownership to the
* ldisc side of the queue. It then schedules those characters for
* processing by the line discipline.
- * Note that this function can only be used when the low_latency flag
- * is unset. Otherwise the workqueue won't be flushed.
*/
void tty_schedule_flip(struct tty_port *port)
{
struct tty_bufhead *buf = &port->buf;
- WARN_ON(port->low_latency);
buf->tail->commit = buf->tail->used;
schedule_work(&buf->work);
@@ -482,17 +479,15 @@ static void flush_to_ldisc(struct work_s
*/
void tty_flush_to_ldisc(struct tty_struct *tty)
{
- if (!tty->port->low_latency)
- flush_work(&tty->port->buf.work);
+ flush_work(&tty->port->buf.work);
}
/**
* tty_flip_buffer_push - terminal
* @port: tty port to push
*
- * Queue a push of the terminal flip buffers to the line discipline. This
- * function must not be called from IRQ context if port->low_latency is
- * set.
+ * Queue a push of the terminal flip buffers to the line discipline.
+ * Can be called from IRQ/atomic context.
*
* In the event of the queue being busy for flipping the work will be
* held off and retried later.
@@ -500,14 +495,7 @@ void tty_flush_to_ldisc(struct tty_struc
void tty_flip_buffer_push(struct tty_port *port)
{
- struct tty_bufhead *buf = &port->buf;
-
- buf->tail->commit = buf->tail->used;
-
- if (port->low_latency)
- flush_to_ldisc(&buf->work);
- else
- schedule_work(&buf->work);
+ tty_schedule_flip(port);
}
EXPORT_SYMBOL(tty_flip_buffer_push);
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -549,8 +549,8 @@ static void gs_rx_push(unsigned long _po
port->read_started--;
}
- /* Push from tty to ldisc; without low_latency set this is handled by
- * a workqueue, so we won't get callbacks and can hold port_lock
+ /* Push from tty to ldisc; this is handled by a workqueue,
+ * so we won't get callbacks and can hold port_lock
*/
if (do_push)
tty_flip_buffer_push(&port->port);
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -208,7 +208,7 @@ struct tty_port {
wait_queue_head_t delta_msr_wait; /* Modem status change */
unsigned long flags; /* TTY flags ASY_*/
unsigned char console:1, /* port is a console */
- low_latency:1; /* direct buffer flush */
+ low_latency:1; /* optional: tune for latency */
struct mutex mutex; /* Locking */
struct mutex buf_mutex; /* Buffer alloc lock */
unsigned char *xmit_buf; /* Optional buffer */
next prev parent reply other threads:[~2014-04-24 21:48 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-24 21:48 [PATCH 3.14 00/33] 3.14.2-stable review Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 01/33] user namespace: fix incorrect memory barriers Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 02/33] Char: ipmi_bt_sm, fix infinite loop Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 03/33] x86, hyperv: Bypass the timer_irq_works() check Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 04/33] x86: Adjust irq remapping quirk for older revisions of 5500/5520 chipsets Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 05/33] PCI: designware: Fix RC BAR to be single 64-bit non-prefetchable memory BAR Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 06/33] PCI: designware: Fix iATU programming for cfg1, io and mem viewport Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 07/33] ACPI / button: Add ACPI Button event via netlink routine Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 08/33] staging: comedi: 8255_pci: initialize MITE data window Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 09/33] staging: comedi: fix circular locking dependency in comedi_mmap() Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 10/33] kernfs: fix off by one error Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 11/33] kernfs: protect lazy kernfs_iattrs allocation with mutex Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 12/33] tty: Set correct tty name in active sysfs attribute Greg Kroah-Hartman
2014-04-24 21:48 ` Greg Kroah-Hartman [this message]
2014-04-24 21:48 ` [PATCH 3.14 14/33] SCSI: sd: dont fail if the device doesnt recognize SYNCHRONIZE CACHE Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 16/33] Bluetooth: Fix removing Long Term Key Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 17/33] ima: restore the original behavior for sending data with ima template Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 18/33] backing_dev: fix hung task on sync Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 19/33] bdi: avoid oops on device removal Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 20/33] xfs: fix directory hash ordering bug Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 21/33] Btrfs: skip submitting barrier for missing device Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 22/33] Btrfs: fix deadlock with nested trans handles Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 23/33] Btrfs: check for an extent_op on the locked ref Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 24/33] ext4: fix error return from ext4_ext_handle_uninitialized_extents() Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 25/33] ext4: fix partial cluster handling for bigalloc file systems Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 26/33] ext4: fix premature freeing of partial clusters split across leaf blocks Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 27/33] fs: NULL dereference in posix_acl_to_xattr() Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 28/33] jffs2: Fix segmentation fault found in stress test Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 29/33] jffs2: Fix crash due to truncation of csize Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 30/33] jffs2: avoid soft-lockup in jffs2_reserve_space_gc() Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 31/33] jffs2: remove from wait queue after schedule() Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 32/33] wait: fix reparent_leader() vs EXIT_DEAD->EXIT_ZOMBIE race Greg Kroah-Hartman
2014-04-24 21:48 ` [PATCH 3.14 33/33] exit: call disassociate_ctty() before exit_task_namespaces() Greg Kroah-Hartman
2014-04-25 0:21 ` [PATCH 3.14 00/33] 3.14.2-stable review Guenter Roeck
2014-04-25 1:49 ` Greg Kroah-Hartman
2014-04-25 17:02 ` Shuah Khan
2014-04-25 17:29 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140424214451.485776143@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=alan@linux.intel.com \
--cc=bbolli@ewanet.ch \
--cc=dsterba@suse.cz \
--cc=grant.b.edwards@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=murray+fedora@ip-64-139-1-69.sjc.megapath.net \
--cc=peter@hurleysoftware.com \
--cc=proski@gnu.org \
--cc=sgruszka@redhat.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).