]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
pipe: change pipe_write() to never add a zero-sized buffer
authorOleg Nesterov <oleg@redhat.com>
Mon, 10 Feb 2025 11:40:39 +0000 (12:40 +0100)
committerChristian Brauner <brauner@kernel.org>
Wed, 12 Feb 2025 14:34:56 +0000 (15:34 +0100)
commitee5eda8ea59546af2e8f192c060fbf29862d7cbd
tree6329df5bbbe459f65e538f5c6ae34c823a2fe035
parentf2ffc48de2017c690f3e7cb34ae7acf40842babc
pipe: change pipe_write() to never add a zero-sized buffer

a194dfe6e6f6 ("pipe: Rearrange sequence in pipe_write() to preallocate slot")
changed pipe_write() to increment pipe->head in advance.  IIUC to avoid the
race with the post_one_notification()-like code which can add another buffer
under pipe->rd_wait.lock without pipe->mutex.

This is no longer necessary after c73be61cede5 ("pipe: Add general notification
queue support"), pipe_write() checks pipe_has_watch_queue() and returns -EXDEV
at the start. And can't help in any case, pipe_write() no longer takes this
rd_wait.lock spinlock.

Change pipe_write() to call copy_page_from_iter() first and do nothing if it
fails. This way pipe_write() can't add a zero-sized buffer and we can simplify
pipe_read() which currently has to take care of this very unlikely case.

Also, with this patch we can probably kill eat_empty_buffer() and more
"is this buffer empty" checks in fs/splice.c later.

Link: https://lore.kernel.org/all/20250209150718.GA17013@redhat.com/
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Link: https://lore.kernel.org/r/20250210114039.GA3588@redhat.com
Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/pipe.c