Can't read and write simultaneously from serial port

Bug #1815021 reported by Strelok on 2019-02-07
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux-signed-hwe (Ubuntu)

Bug Description

With linux kernel <=4.15.0-43 I can start reading serial device (TTY) in block mode and write from another process at the same time (simultaneously). After update to 4.15.0-45 I can't.

[Steps to reproduce]
1) Run in terminal:
cat /dev/ttyS0
"cat" must block terminal and wait for data.
2) Run in another terminal:
echo > /dev/ttyS0

"cat" continue wait data and not exit.

"cat" exit with return code "1" and show error -EAGAIN (-11):
"cat: /dev/ttyS0: Resource temporarily unavailable"

I think it's regression in kernel, due to new ldisc checks in TTY driver. Please see:
git diff Ubuntu-hwe-4.15.0-43.46_16.04.1 Ubuntu-hwe-4.15.0-45.48_16.04.1 -- drivers/tty/tty_ldisc.c
git diff Ubuntu-hwe-4.15.0-43.46_16.04.1 Ubuntu-hwe-4.15.0-45.48_16.04.1 -- drivers/tty/n_tty.c

diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index 0fd18f5..48fe8d9 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -340,6 +340,11 @@ int tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout)
        int ret;

+ /* Kindly asking blocked readers to release the read side */
+ set_bit(TTY_LDISC_CHANGING, &tty->flags);
+ wake_up_interruptible_all(&tty->read_wait);
+ wake_up_interruptible_all(&tty->write_wait);
        ret = __tty_ldisc_lock(tty, timeout);
        if (!ret)
                return -EBUSY;

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 63c593a..9805ac1 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2188,7 +2197,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
                                if (!timeout)
- if (file->f_flags & O_NONBLOCK) {
+ if (tty_io_nonblock(tty, file)) {
                                        retval = -EAGAIN;
@@ -2342,7 +2351,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
                if (!nr)
- if (file->f_flags & O_NONBLOCK) {
+ if (tty_io_nonblock(tty, file)) {
                        retval = -EAGAIN;

ProblemType: Bug
DistroRelease: Ubuntu 16.04
Package: linux-image-4.15.0-45-generic 4.15.0-45.48~16.04.1
ProcVersionSignature: Ubuntu 4.15.0-45.48~16.04.1-generic 4.15.18
Uname: Linux 4.15.0-45-generic x86_64
NonfreeKernelModules: nvidia_uvm nvidia_drm nvidia_modeset nvidia
ApportVersion: 2.20.1-0ubuntu2.18
Architecture: amd64
CurrentDesktop: MATE
Date: Thu Feb 7 11:42:43 2019
InstallationDate: Installed on 2017-08-01 (554 days ago)
InstallationMedia: Ubuntu 16.04.2 LTS "Xenial Xerus" - Release amd64 (20170215.2)
SourcePackage: linux-signed-hwe
UpgradeStatus: No upgrade log present (probably fresh install)

Strelok (who-) wrote :

$ bash -c 'sleep 1 && : < /dev/tty & read var' < /dev/tty
bash: line 0: read: read error: 0: Resource temporarily unavailable

seems to be related and is possibly the same bug. See

Strelok (who-) wrote :

Fixed for me in 4.15.0-46.
Thank you for reply.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers