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

Configure Feed

Select the types of activity you want to include in your feed.

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: ddf0322db79c ("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>

authored by

Gabriel Krisman Bertazi and committed by
Jens Axboe
f74c746e ab69838e

+7 -4
+7 -4
io_uring/kbuf.c
··· 19 19 20 20 #define BGID_ARRAY 64 21 21 22 + /* BIDs are addressed by a 16-bit field in a CQE */ 23 + #define MAX_BIDS_PER_BGID (1 << 16) 24 + 22 25 struct io_provide_buf { 23 26 struct file *file; 24 27 __u64 addr; 25 28 __u32 len; 26 29 __u32 bgid; 27 - __u16 nbufs; 30 + __u32 nbufs; 28 31 __u16 bid; 29 32 }; 30 33 ··· 292 289 return -EINVAL; 293 290 294 291 tmp = READ_ONCE(sqe->fd); 295 - if (!tmp || tmp > USHRT_MAX) 292 + if (!tmp || tmp > MAX_BIDS_PER_BGID) 296 293 return -EINVAL; 297 294 298 295 memset(p, 0, sizeof(*p)); ··· 335 332 return -EINVAL; 336 333 337 334 tmp = READ_ONCE(sqe->fd); 338 - if (!tmp || tmp > USHRT_MAX) 335 + if (!tmp || tmp > MAX_BIDS_PER_BGID) 339 336 return -E2BIG; 340 337 p->nbufs = tmp; 341 338 p->addr = READ_ONCE(sqe->addr); ··· 355 352 tmp = READ_ONCE(sqe->off); 356 353 if (tmp > USHRT_MAX) 357 354 return -E2BIG; 358 - if (tmp + p->nbufs > USHRT_MAX) 355 + if (tmp + p->nbufs > MAX_BIDS_PER_BGID) 359 356 return -EINVAL; 360 357 p->bid = tmp; 361 358 return 0;