pipe: Rearrange sequence in pipe_write() to preallocate slot
authorDavid Howells <dhowells@redhat.com>
Fri, 20 Sep 2019 15:32:19 +0000 (16:32 +0100)
committerDavid Howells <dhowells@redhat.com>
Fri, 15 Nov 2019 16:22:54 +0000 (16:22 +0000)
commita194dfe6e6f6f7205eea850a420f2bc6a1541209
tree5a3a0aa3ac86e1f73ee347b7ab28d3e86a4dda39
parent8446487feba988a92e7649c60367510f0b0445a8
pipe: Rearrange sequence in pipe_write() to preallocate slot

Rearrange the sequence in pipe_write() so that the allocation of the new
buffer, the allocation of a ring slot and the attachment to the ring is
done under the pipe wait spinlock and then the lock is dropped and the
buffer can be filled.

The data copy needs to be done with the spinlock unheld and irqs enabled,
so the lock needs to be dropped first.  However, the reader can't progress
as we're holding pipe->mutex.

We also need to drop the lock as that would impact others looking at the
pipe waitqueue, such as poll(), the consumer and a future kernel message
writer.

We just abandon the preallocated slot if we get a copy error.  Future
writes may continue it and a future read will eventually recycle it.

Signed-off-by: David Howells <dhowells@redhat.com>
fs/pipe.c