]> git.baikalelectronics.ru Git - kernel.git/commit
pipe: fix empty pipe check in pipe_write()
authorJan Stancek <jstancek@redhat.com>
Sun, 22 Dec 2019 12:33:24 +0000 (13:33 +0100)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 22 Dec 2019 17:47:47 +0000 (09:47 -0800)
commitb9697412d0051b2479bcbe34808f5237e181b5b2
tree65b6d77c5be91eb0104945af6598bf8d9718426e
parent3ddbf1af50e35e7dc53b4b134448a60b41da8c23
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: 5c213172f412 ("pipe: fix and clarify pipe write wakeup logic")
Reported-by: Rachel Sibley <rasibley@redhat.com>
Signed-off-by: Jan Stancek <jstancek@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/pipe.c