Skip to content

Commit

Permalink
pipe: fix empty pipe check in pipe_write()
Browse files Browse the repository at this point in the history
LTP pipeio_1 test is hanging with v5.5-rc2-385-gb8e382a185eb,
with read side observing empty pipe and sleeping and write
side running out of space and then sleeping as well. In this
scenario there are 5 writers and 1 reader.

Problem is that after pipe_write() reacquires pipe lock, it
re-checks for empty pipe with potentially stale 'head' and
doesn't wake up read side anymore. pipe->tail can advance
beyond 'head', because there are multiple writers.

Use pipe->head for empty pipe check after reacquiring lock
to observe current state.

Testing: With patch, LTP pipeio_1 ran successfully in loop for 1 hour.
         Without patch it hanged within a minute.

Fixes: 1b6b26a ("pipe: fix and clarify pipe write wakeup logic")
Reported-by: Rachel Sibley <[email protected]>
Signed-off-by: Jan Stancek <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
jstancek authored and torvalds committed Dec 22, 2019
1 parent b8e382a commit 0dd1e37
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fs/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
}
wait_event_interruptible(pipe->wait, pipe_writable(pipe));
__pipe_lock(pipe);
was_empty = pipe_empty(head, pipe->tail);
was_empty = pipe_empty(pipe->head, pipe->tail);
}
out:
__pipe_unlock(pipe);
Expand Down

0 comments on commit 0dd1e37

Please sign in to comment.