Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

io_uring/kbuf: enable bundles for incrementally consumed buffers

The original support for incrementally consumed buffers didn't allow it
to be used with bundles, with the assumption being that incremental
buffers are generally larger, and hence there's less of a nedd to
support it.

But that assumption may not be correct - it's perfectly viable to use
smaller buffers with incremental consumption, and there may be valid
reasons for an application or framework to do so.

As there's really no need to explicitly disable bundles with
incrementally consumed buffers, allow it. This actually makes the peek
side cheaper and simpler, with the completion side basically the same,
just needing to iterate for the consumed length.

Reported-by: Norman Maurer <norman_maurer@apple.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

+26 -30
+26 -30
io_uring/kbuf.c
··· 32 32 __u16 bid; 33 33 }; 34 34 35 + static bool io_kbuf_inc_commit(struct io_buffer_list *bl, int len) 36 + { 37 + while (len) { 38 + struct io_uring_buf *buf; 39 + u32 this_len; 40 + 41 + buf = io_ring_head_to_buf(bl->buf_ring, bl->head, bl->mask); 42 + this_len = min_t(int, len, buf->len); 43 + buf->len -= this_len; 44 + if (buf->len) { 45 + buf->addr += this_len; 46 + return false; 47 + } 48 + bl->head++; 49 + len -= this_len; 50 + } 51 + return true; 52 + } 53 + 35 54 bool io_kbuf_commit(struct io_kiocb *req, 36 55 struct io_buffer_list *bl, int len, int nr) 37 56 { ··· 61 42 62 43 if (unlikely(len < 0)) 63 44 return true; 64 - 65 - if (bl->flags & IOBL_INC) { 66 - struct io_uring_buf *buf; 67 - 68 - buf = io_ring_head_to_buf(bl->buf_ring, bl->head, bl->mask); 69 - if (WARN_ON_ONCE(len > buf->len)) 70 - len = buf->len; 71 - buf->len -= len; 72 - if (buf->len) { 73 - buf->addr += len; 74 - return false; 75 - } 76 - } 77 - 45 + if (bl->flags & IOBL_INC) 46 + return io_kbuf_inc_commit(bl, len); 78 47 bl->head += nr; 79 48 return true; 80 49 } ··· 233 226 buf = io_ring_head_to_buf(br, head, bl->mask); 234 227 if (arg->max_len) { 235 228 u32 len = READ_ONCE(buf->len); 229 + size_t needed; 236 230 237 231 if (unlikely(!len)) 238 232 return -ENOBUFS; 239 - /* 240 - * Limit incremental buffers to 1 segment. No point trying 241 - * to peek ahead and map more than we need, when the buffers 242 - * themselves should be large when setup with 243 - * IOU_PBUF_RING_INC. 244 - */ 245 - if (bl->flags & IOBL_INC) { 246 - nr_avail = 1; 247 - } else { 248 - size_t needed; 249 - 250 - needed = (arg->max_len + len - 1) / len; 251 - needed = min_not_zero(needed, (size_t) PEEK_MAX_IMPORT); 252 - if (nr_avail > needed) 253 - nr_avail = needed; 254 - } 233 + needed = (arg->max_len + len - 1) / len; 234 + needed = min_not_zero(needed, (size_t) PEEK_MAX_IMPORT); 235 + if (nr_avail > needed) 236 + nr_avail = needed; 255 237 } 256 238 257 239 /*