[RFC,10/11] pipe: Check for ring full inside of the spinlock in pipe_write() [ver #3]
diff mbox series

Message ID 157262973277.13142.11996381016183033698.stgit@warthog.procyon.org.uk
State New
Headers show
  • pipe: Notification queue preparation [ver #3]
Related show

Commit Message

David Howells Nov. 1, 2019, 5:35 p.m. UTC
Make pipe_write() check to see if the ring has become full between it
taking the pipe mutex, checking the ring status and then taking the

This can happen if a notification is written into the pipe as that happens
without the pipe mutex.

Signed-off-by: David Howells <dhowells@redhat.com>

 fs/pipe.c |    5 +++++
 1 file changed, 5 insertions(+)

diff mbox series

diff --git a/fs/pipe.c b/fs/pipe.c
index d7b8d3f22987..aba2455caabe 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -463,6 +463,11 @@  pipe_write(struct kiocb *iocb, struct iov_iter *from)
 			head = pipe->head;
+			if (pipe_full(head, pipe->tail, max_usage)) {
+				spin_unlock_irq(&pipe->wait.lock);
+				continue;
+			}
 			pipe->head = head + 1;
 			/* Always wake up, even if the copy fails. Otherwise