* [PATCH] n_tty: wake up poll(POLLRDNORM) on receiving data
@ 2022-01-24 8:17 TATSUKAWA KOSUKE(立川 江介)
2022-01-26 13:49 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: TATSUKAWA KOSUKE(立川 江介) @ 2022-01-24 8:17 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby; +Cc: linux-kernel
Event POLLRDNORM should be equivalent to POLLIN when used as event in
poll(). However, in n_tty driver, POLLRDNORM does not return until
timeout even if there is terminal input, whereas POLLIN returns.
The following test program works until kernel-3.17, but the test stops
in poll() after commit 57087d515441 ("tty: Fix spurious poll() wakeups").
[Steps to run test program]
$ cc -o test-pollrdnorm test-pollrdnorm.c
$ ./test-pollrdnorm
foo <-- Type in something from the terminal followed by [RET].
The string should be echoed back.
------------------------< test-pollrdnorm.c >------------------------
#include <stdio.h>
#include <errno.h>
#include <poll.h>
#include <unistd.h>
void main(void)
{
int n;
unsigned char buf[8];
struct pollfd fds[1] = {{ 0, POLLRDNORM, 0 }};
n = poll(fds, 1, -1);
if (n < 0)
perror("poll");
n = read(0, buf, 8);
if (n < 0)
perror("read");
if (n > 0)
write(1, buf, n);
}
------------------------------------------------------------------------
The attached patch fixes this problem.
Signed-off-by: Kosuke Tatsukawa <tatsu-ab1@nec.com>
Fixes: commit 57087d515441 ("tty: Fix spurious poll() wakeups")
Cc: stable@vger.kernel.org
---
drivers/tty/n_tty.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 5be6d02..b2b98fe 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1369,7 +1369,7 @@ static void n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
put_tty_queue(c, ldata);
smp_store_release(&ldata->canon_head, ldata->read_head);
kill_fasync(&tty->fasync, SIGIO, POLL_IN);
- wake_up_interruptible_poll(&tty->read_wait, EPOLLIN);
+ wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM);
return;
}
}
@@ -1589,7 +1589,7 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
if (read_cnt(ldata)) {
kill_fasync(&tty->fasync, SIGIO, POLL_IN);
- wake_up_interruptible_poll(&tty->read_wait, EPOLLIN);
+ wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM);
}
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] n_tty: wake up poll(POLLRDNORM) on receiving data
2022-01-24 8:17 [PATCH] n_tty: wake up poll(POLLRDNORM) on receiving data TATSUKAWA KOSUKE(立川 江介)
@ 2022-01-26 13:49 ` Greg Kroah-Hartman
2022-01-26 23:34 ` TATSUKAWA KOSUKE(立川 江介)
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2022-01-26 13:49 UTC (permalink / raw)
To: TATSUKAWA KOSUKE(立川 江介)
Cc: Jiri Slaby, linux-kernel
On Mon, Jan 24, 2022 at 08:17:22AM +0000, TATSUKAWA KOSUKE(立川 江介) wrote:
> Event POLLRDNORM should be equivalent to POLLIN when used as event in
> poll().
Where is that documented?
> However, in n_tty driver, POLLRDNORM does not return until
> timeout even if there is terminal input, whereas POLLIN returns.
>
> The following test program works until kernel-3.17, but the test stops
> in poll() after commit 57087d515441 ("tty: Fix spurious poll() wakeups").
>
> [Steps to run test program]
> $ cc -o test-pollrdnorm test-pollrdnorm.c
> $ ./test-pollrdnorm
> foo <-- Type in something from the terminal followed by [RET].
> The string should be echoed back.
>
> ------------------------< test-pollrdnorm.c >------------------------
> #include <stdio.h>
> #include <errno.h>
> #include <poll.h>
> #include <unistd.h>
>
> void main(void)
> {
> int n;
> unsigned char buf[8];
> struct pollfd fds[1] = {{ 0, POLLRDNORM, 0 }};
>
> n = poll(fds, 1, -1);
> if (n < 0)
> perror("poll");
> n = read(0, buf, 8);
> if (n < 0)
> perror("read");
> if (n > 0)
> write(1, buf, n);
> }
> ------------------------------------------------------------------------
>
> The attached patch fixes this problem.
>
> Signed-off-by: Kosuke Tatsukawa <tatsu-ab1@nec.com>
> Fixes: commit 57087d515441 ("tty: Fix spurious poll() wakeups")
No need for "commit" here, please remove as the documentation asks you
to.
Can you resend this with this fixed up, and a pointer to where the
documentation is for this functionality.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] n_tty: wake up poll(POLLRDNORM) on receiving data
2022-01-26 13:49 ` Greg Kroah-Hartman
@ 2022-01-26 23:34 ` TATSUKAWA KOSUKE(立川 江介)
0 siblings, 0 replies; 3+ messages in thread
From: TATSUKAWA KOSUKE(立川 江介) @ 2022-01-26 23:34 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Jiri Slaby, linux-kernel
Hi, thank you for the reply.
> On Mon, Jan 24, 2022 at 08:17:22AM +0000, TATSUKAWA KOSUKE(立川 江介) wrote:
> > Event POLLRDNORM should be equivalent to POLLIN when used as event in
> > poll().
>
> Where is that documented?
It's in "man poll". Below is an excerpt from the man page.
POLLRDNORM
Equivalent to POLLIN.
I'll send a v2 patch in a separate message.
Many other calls to wake_up_interruptible_poll() in the kernel source
code already specify "POLLIN | POLLRDNORM", but there are places under
drivers/tty which only passes POLLIN (i.e. pty.c, tty_io.c,
tty_ldisc.c). I haven't yet made test programs to hit the other
locations and I wasn't sure if they should also be fixed just for
consistency.
Best regards.
> > However, in n_tty driver, POLLRDNORM does not return until
> > timeout even if there is terminal input, whereas POLLIN returns.
> >
> > The following test program works until kernel-3.17, but the test stops
> > in poll() after commit 57087d515441 ("tty: Fix spurious poll() wakeups").
> >
> > [Steps to run test program]
> > $ cc -o test-pollrdnorm test-pollrdnorm.c
> > $ ./test-pollrdnorm
> > foo <-- Type in something from the terminal followed by [RET].
> > The string should be echoed back.
> >
> > ------------------------< test-pollrdnorm.c >------------------------
> > #include <stdio.h>
> > #include <errno.h>
> > #include <poll.h>
> > #include <unistd.h>
> >
> > void main(void)
> > {
> > int n;
> > unsigned char buf[8];
> > struct pollfd fds[1] = {{ 0, POLLRDNORM, 0 }};
> >
> > n = poll(fds, 1, -1);
> > if (n < 0)
> > perror("poll");
> > n = read(0, buf, 8);
> > if (n < 0)
> > perror("read");
> > if (n > 0)
> > write(1, buf, n);
> > }
> > ------------------------------------------------------------------------
> >
> > The attached patch fixes this problem.
> >
> > Signed-off-by: Kosuke Tatsukawa <tatsu-ab1@nec.com>
> > Fixes: commit 57087d515441 ("tty: Fix spurious poll() wakeups")
>
> No need for "commit" here, please remove as the documentation asks you
> to.
>
> Can you resend this with this fixed up, and a pointer to where the
> documentation is for this functionality.
>
> thanks,
>
> greg k-h
---
Kosuke TATSUKAWA | 1st Platform Software Division
| NEC Solution Innovators
| tatsu-ab1@nec.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-01-26 23:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 8:17 [PATCH] n_tty: wake up poll(POLLRDNORM) on receiving data TATSUKAWA KOSUKE(立川 江介)
2022-01-26 13:49 ` Greg Kroah-Hartman
2022-01-26 23:34 ` TATSUKAWA KOSUKE(立川 江介)
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).