diff mbox series

[RFC,08/21] pipe: Check for ring full inside of the spinlock in pipe_write()

Message ID 157117614109.15019.15677943675625422728.stgit@warthog.procyon.org.uk (mailing list archive)
State New, archived
Headers show
Series pipe: Keyrings, Block and USB notifications | expand

Commit Message

David Howells Oct. 15, 2019, 9:49 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
spinlock.

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(+)

Comments

Linus Torvalds Oct. 15, 2019, 10:20 p.m. UTC | #1
On Tue, Oct 15, 2019 at 2:49 PM David Howells <dhowells@redhat.com> wrote:
>
> +                       if (head - pipe->tail == buffers) {

Can we just have helper inline functions for these things?

You describe them in the commit message of 03/21 (good), but it would
be even better if the code was just self-describing..

           Linus
diff mbox series

Patch

diff --git a/fs/pipe.c b/fs/pipe.c
index 289a887f6b5b..0255a5ca5097 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -462,6 +462,11 @@  pipe_write(struct kiocb *iocb, struct iov_iter *from)
 			spin_lock_irq(&pipe->wait.lock);
 
 			head = pipe->head;
+			if (head - pipe->tail == buffers) {
+				spin_unlock_irq(&pipe->wait.lock);
+				continue;
+			}
+
 			pipe_commit_write(pipe, head + 1);
 
 			/* Always wake up, even if the copy fails. Otherwise