Merge patch series "pipe: Trivial cleanups"
authorChristian Brauner <brauner@kernel.org>
Mon, 10 Mar 2025 07:55:13 +0000 (08:55 +0100)
committerChristian Brauner <brauner@kernel.org>
Mon, 10 Mar 2025 07:55:13 +0000 (08:55 +0100)
K Prateek Nayak <kprateek.nayak@amd.com> says:

Based on the suggestion on the RFC, the treewide conversion of
references to pipe->{head,tail} from unsigned int to pipe_index_t has
been dropped for now. The series contains trivial cleanup suggested to
limit the nr_slots in pipe_resize_ring() to be covered between
pipe_index_t limits of pipe->{head,tail} and using pipe_buf() to remove
the open-coded usage of masks to access pipe buffer building on Linus'
cleanup of fs/fuse/dev.c in commit ebb0f38bb47f ("fs/pipe: fix pipe
buffer index use in FUSE")

* patches from https://lore.kernel.org/r/20250307052919.34542-1-kprateek.nayak@amd.com:
  fs/splice: Use pipe_buf() helper to retrieve pipe buffer
  fs/pipe: Use pipe_buf() helper to retrieve pipe buffer
  kernel/watch_queue: Use pipe_buf() to retrieve the pipe buffer
  fs/pipe: Limit the slots in pipe_resize_ring()

Link: https://lore.kernel.org/r/20250307052919.34542-1-kprateek.nayak@amd.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
1  2 
fs/pipe.c

diff --cc fs/pipe.c
index 47e96192898d42003f4ec826cbd81cc0022bf127,4d6ca0f892b1cc2683a925c7831140f061eb392c..da45edd68c4166908b25e70e54b2430bbfcb7671
+++ b/fs/pipe.c
@@@ -509,29 -501,28 +507,28 @@@ anon_pipe_write(struct kiocb *iocb, str
  
                head = pipe->head;
                if (!pipe_full(head, pipe->tail, pipe->max_usage)) {
-                       unsigned int mask = pipe->ring_size - 1;
                        struct pipe_buffer *buf;
 -                      struct page *page = pipe->tmp_page;
 +                      struct page *page;
                        int copied;
  
 -                      if (!page) {
 -                              page = alloc_page(GFP_HIGHUSER | __GFP_ACCOUNT);
 -                              if (unlikely(!page)) {
 -                                      ret = ret ? : -ENOMEM;
 -                                      break;
 -                              }
 -                              pipe->tmp_page = page;
 +                      page = anon_pipe_get_page(pipe);
 +                      if (unlikely(!page)) {
 +                              if (!ret)
 +                                      ret = -ENOMEM;
 +                              break;
                        }
  
 -                      /* Allocate a slot in the ring in advance and attach an
 -                       * empty buffer.  If we fault or otherwise fail to use
 -                       * it, either the reader will consume it or it'll still
 -                       * be there for the next write.
 -                       */
 -                      pipe->head = head + 1;
 +                      copied = copy_page_from_iter(page, 0, PAGE_SIZE, from);
 +                      if (unlikely(copied < PAGE_SIZE && iov_iter_count(from))) {
 +                              anon_pipe_put_page(pipe, page);
 +                              if (!ret)
 +                                      ret = -EFAULT;
 +                              break;
 +                      }
  
 +                      pipe->head = head + 1;
                        /* Insert it into the buffer array */
-                       buf = &pipe->bufs[head & mask];
+                       buf = pipe_buf(pipe, head);
                        buf->page = page;
                        buf->ops = &anon_pipe_buf_ops;
                        buf->offset = 0;