Skip to content

Commit 0dd1e37

Browse files
jstancektorvalds
authored andcommitted
pipe: fix empty pipe check in pipe_write()
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]>
1 parent b8e382a commit 0dd1e37

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/pipe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
581581
}
582582
wait_event_interruptible(pipe->wait, pipe_writable(pipe));
583583
__pipe_lock(pipe);
584-
was_empty = pipe_empty(head, pipe->tail);
584+
was_empty = pipe_empty(pipe->head, pipe->tail);
585585
}
586586
out:
587587
__pipe_unlock(pipe);

0 commit comments

Comments
 (0)