Skip to content

Commit 5d3e512

Browse files
isilenceaxboe
authored andcommitted
io_uring/kbuf: uninline __io_put_kbufs
__io_put_kbufs() and other helper functions are too large to be inlined, compilers would normally refuse to do so. Uninline it and move together with io_kbuf_commit into kbuf.c. io_kbuf_commitSigned-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/3dade7f55ad590e811aff83b1ec55c9c04e17b2b.1738724373.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 54e00d9 commit 5d3e512

2 files changed

Lines changed: 70 additions & 64 deletions

File tree

io_uring/kbuf.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
/* BIDs are addressed by a 16-bit field in a CQE */
2121
#define MAX_BIDS_PER_BGID (1 << 16)
2222

23+
/* Mapped buffer ring, return io_uring_buf from head */
24+
#define io_ring_head_to_buf(br, head, mask) &(br)->bufs[(head) & (mask)]
25+
2326
struct io_provide_buf {
2427
struct file *file;
2528
__u64 addr;
@@ -29,6 +32,34 @@ struct io_provide_buf {
2932
__u16 bid;
3033
};
3134

35+
bool io_kbuf_commit(struct io_kiocb *req,
36+
struct io_buffer_list *bl, int len, int nr)
37+
{
38+
if (unlikely(!(req->flags & REQ_F_BUFFERS_COMMIT)))
39+
return true;
40+
41+
req->flags &= ~REQ_F_BUFFERS_COMMIT;
42+
43+
if (unlikely(len < 0))
44+
return true;
45+
46+
if (bl->flags & IOBL_INC) {
47+
struct io_uring_buf *buf;
48+
49+
buf = io_ring_head_to_buf(bl->buf_ring, bl->head, bl->mask);
50+
if (WARN_ON_ONCE(len > buf->len))
51+
len = buf->len;
52+
buf->len -= len;
53+
if (buf->len) {
54+
buf->addr += len;
55+
return false;
56+
}
57+
}
58+
59+
bl->head += nr;
60+
return true;
61+
}
62+
3263
static inline struct io_buffer_list *io_buffer_get_list(struct io_ring_ctx *ctx,
3364
unsigned int bgid)
3465
{
@@ -323,6 +354,35 @@ int io_buffers_peek(struct io_kiocb *req, struct buf_sel_arg *arg)
323354
return io_provided_buffers_select(req, &arg->max_len, bl, arg->iovs);
324355
}
325356

357+
static inline bool __io_put_kbuf_ring(struct io_kiocb *req, int len, int nr)
358+
{
359+
struct io_buffer_list *bl = req->buf_list;
360+
bool ret = true;
361+
362+
if (bl) {
363+
ret = io_kbuf_commit(req, bl, len, nr);
364+
req->buf_index = bl->bgid;
365+
}
366+
req->flags &= ~REQ_F_BUFFER_RING;
367+
return ret;
368+
}
369+
370+
unsigned int __io_put_kbufs(struct io_kiocb *req, int len, int nbufs)
371+
{
372+
unsigned int ret;
373+
374+
ret = IORING_CQE_F_BUFFER | (req->buf_index << IORING_CQE_BUFFER_SHIFT);
375+
376+
if (unlikely(!(req->flags & REQ_F_BUFFER_RING))) {
377+
io_kbuf_drop_legacy(req);
378+
return ret;
379+
}
380+
381+
if (!__io_put_kbuf_ring(req, len, nbufs))
382+
ret |= IORING_CQE_F_BUF_MORE;
383+
return ret;
384+
}
385+
326386
static int __io_remove_buffers(struct io_ring_ctx *ctx,
327387
struct io_buffer_list *bl, unsigned nbufs)
328388
{

io_uring/kbuf.h

Lines changed: 10 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ int io_register_pbuf_status(struct io_ring_ctx *ctx, void __user *arg);
7777
bool io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags);
7878
void io_kbuf_drop_legacy(struct io_kiocb *req);
7979

80+
unsigned int __io_put_kbufs(struct io_kiocb *req, int len, int nbufs);
81+
bool io_kbuf_commit(struct io_kiocb *req,
82+
struct io_buffer_list *bl, int len, int nr);
83+
8084
struct io_mapped_region *io_pbuf_get_region(struct io_ring_ctx *ctx,
8185
unsigned int bgid);
8286

@@ -115,77 +119,19 @@ static inline bool io_kbuf_recycle(struct io_kiocb *req, unsigned issue_flags)
115119
return false;
116120
}
117121

118-
/* Mapped buffer ring, return io_uring_buf from head */
119-
#define io_ring_head_to_buf(br, head, mask) &(br)->bufs[(head) & (mask)]
120-
121-
static inline bool io_kbuf_commit(struct io_kiocb *req,
122-
struct io_buffer_list *bl, int len, int nr)
123-
{
124-
if (unlikely(!(req->flags & REQ_F_BUFFERS_COMMIT)))
125-
return true;
126-
127-
req->flags &= ~REQ_F_BUFFERS_COMMIT;
128-
129-
if (unlikely(len < 0))
130-
return true;
131-
132-
if (bl->flags & IOBL_INC) {
133-
struct io_uring_buf *buf;
134-
135-
buf = io_ring_head_to_buf(bl->buf_ring, bl->head, bl->mask);
136-
if (WARN_ON_ONCE(len > buf->len))
137-
len = buf->len;
138-
buf->len -= len;
139-
if (buf->len) {
140-
buf->addr += len;
141-
return false;
142-
}
143-
}
144-
145-
bl->head += nr;
146-
return true;
147-
}
148-
149-
static inline bool __io_put_kbuf_ring(struct io_kiocb *req, int len, int nr)
150-
{
151-
struct io_buffer_list *bl = req->buf_list;
152-
bool ret = true;
153-
154-
if (bl) {
155-
ret = io_kbuf_commit(req, bl, len, nr);
156-
req->buf_index = bl->bgid;
157-
}
158-
req->flags &= ~REQ_F_BUFFER_RING;
159-
return ret;
160-
}
161-
162-
static inline unsigned int __io_put_kbufs(struct io_kiocb *req, int len,
163-
int nbufs, unsigned issue_flags)
164-
{
165-
unsigned int ret;
166-
167-
if (!(req->flags & (REQ_F_BUFFER_RING | REQ_F_BUFFER_SELECTED)))
168-
return 0;
169-
170-
ret = IORING_CQE_F_BUFFER | (req->buf_index << IORING_CQE_BUFFER_SHIFT);
171-
if (req->flags & REQ_F_BUFFER_RING) {
172-
if (!__io_put_kbuf_ring(req, len, nbufs))
173-
ret |= IORING_CQE_F_BUF_MORE;
174-
} else {
175-
io_kbuf_drop_legacy(req);
176-
}
177-
return ret;
178-
}
179-
180122
static inline unsigned int io_put_kbuf(struct io_kiocb *req, int len,
181123
unsigned issue_flags)
182124
{
183-
return __io_put_kbufs(req, len, 1, issue_flags);
125+
if (!(req->flags & (REQ_F_BUFFER_RING | REQ_F_BUFFER_SELECTED)))
126+
return 0;
127+
return __io_put_kbufs(req, len, 1);
184128
}
185129

186130
static inline unsigned int io_put_kbufs(struct io_kiocb *req, int len,
187131
int nbufs, unsigned issue_flags)
188132
{
189-
return __io_put_kbufs(req, len, nbufs, issue_flags);
133+
if (!(req->flags & (REQ_F_BUFFER_RING | REQ_F_BUFFER_SELECTED)))
134+
return 0;
135+
return __io_put_kbufs(req, len, nbufs);
190136
}
191137
#endif

0 commit comments

Comments
 (0)