Skip to content

Commit f74c746

Browse files
krismanaxboe
authored andcommitted
io_uring/kbuf: Allow the full buffer id space for provided buffers
nbufs tracks the number of buffers and not the last bgid. In 16-bit, we have 2^16 valid buffers, but the check mistakenly rejects the last bid. Let's fix it to make the interface consistent with the documentation. Fixes: ddf0322 ("io_uring: add IORING_OP_PROVIDE_BUFFERS") Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de> Link: https://lore.kernel.org/r/20231005000531.30800-3-krisman@suse.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ab69838 commit f74c746

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

io_uring/kbuf.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919

2020
#define BGID_ARRAY 64
2121

22+
/* BIDs are addressed by a 16-bit field in a CQE */
23+
#define MAX_BIDS_PER_BGID (1 << 16)
24+
2225
struct io_provide_buf {
2326
struct file *file;
2427
__u64 addr;
2528
__u32 len;
2629
__u32 bgid;
27-
__u16 nbufs;
30+
__u32 nbufs;
2831
__u16 bid;
2932
};
3033

@@ -289,7 +292,7 @@ int io_remove_buffers_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
289292
return -EINVAL;
290293

291294
tmp = READ_ONCE(sqe->fd);
292-
if (!tmp || tmp > USHRT_MAX)
295+
if (!tmp || tmp > MAX_BIDS_PER_BGID)
293296
return -EINVAL;
294297

295298
memset(p, 0, sizeof(*p));
@@ -332,7 +335,7 @@ int io_provide_buffers_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
332335
return -EINVAL;
333336

334337
tmp = READ_ONCE(sqe->fd);
335-
if (!tmp || tmp > USHRT_MAX)
338+
if (!tmp || tmp > MAX_BIDS_PER_BGID)
336339
return -E2BIG;
337340
p->nbufs = tmp;
338341
p->addr = READ_ONCE(sqe->addr);
@@ -352,7 +355,7 @@ int io_provide_buffers_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
352355
tmp = READ_ONCE(sqe->off);
353356
if (tmp > USHRT_MAX)
354357
return -E2BIG;
355-
if (tmp + p->nbufs > USHRT_MAX)
358+
if (tmp + p->nbufs > MAX_BIDS_PER_BGID)
356359
return -EINVAL;
357360
p->bid = tmp;
358361
return 0;

0 commit comments

Comments
 (0)