lkml.org 
[lkml]   [2018]   [Dec]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH] tty/n_hdlc: fix sleep in !TASK_RUNNING state warning
From
Date


On Dec 31, 2018, at 7:11 PM, Paul Fulghum <paulkf@microgate.com> wrote:

NAK to this patch. It causes lost wakeups in both read and write paths.

The write path does not need changing.

The read path can be fixed by setting current to TASK_RUNNING at the top of the if (rbuf) block so the warning is not triggered by copy_to_user(). If this block runs the condition is satisfied and it breaks out of the polling loop where it is already being set to TASK_RUNNING and removed from the wait queue. This particular path just needs to account for the copy_to_user which occurs before breaking out.

I’ll make a patch to do this when I have the ability to test it in a day or two.


> On Dec 29, 2018, at 3:48 AM, Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:
>
> syzbot is hitting __might_sleep() warning [1], for commit 1035b63d3c6fc34a
> ("n_hdlc: fix read and write locking") changed to set TASK_INTERRUPTIBLE
> state before calling copy_to_user(). Let's set TASK_INTERRUPTIBLE state
> immediately before calling schedule().
>
> [1] https://syzkaller.appspot.com/bug?id=17d5de7f1fcab794cb8c40032f893f52de899324
>
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Reported-by: syzbot <syzbot+c244af085a0159d22879@syzkaller.appspotmail.com>
> Cc: Paul Fulghum <paulkf@microgate.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
> ---
> drivers/tty/n_hdlc.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
> index dabb391..7835489 100644
> --- a/drivers/tty/n_hdlc.c
> +++ b/drivers/tty/n_hdlc.c
> @@ -589,8 +589,6 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
> if (tty_hung_up_p(file))
> break;
>
> - set_current_state(TASK_INTERRUPTIBLE);
> -
> rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list);
> if (rbuf) {
> if (rbuf->count > nr) {
> @@ -617,6 +615,7 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
> break;
> }
>
> + set_current_state(TASK_INTERRUPTIBLE);
> schedule();
>
> if (signal_pending(current)) {
> @@ -673,8 +672,6 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
> add_wait_queue(&tty->write_wait, &wait);
>
> for (;;) {
> - set_current_state(TASK_INTERRUPTIBLE);
> -
> tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list);
> if (tbuf)
> break;
> @@ -683,6 +680,8 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
> error = -EAGAIN;
> break;
> }
> +
> + set_current_state(TASK_INTERRUPTIBLE);
> schedule();
>
> n_hdlc = tty2n_hdlc (tty);
> --
> 1.8.3.1
>
>

--
Paul Fulghum
MicroGate Systems, Ltd.
=Customer Driven, by Design=
(512) 345-7791 x102 (Voice)
(512) 343-9046 (Fax)
Central Time Zone (GMT -5h)
www.microgate.com

\
 
 \ /
  Last update: 2019-01-01 04:14    [W:0.102 / U:1.560 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site