Commit 88ec3211 authored by Jens Axboe's avatar Jens Axboe

io_uring: round-up cq size before comparing with rounded sq size

If an application specifies IORING_SETUP_CQSIZE to set the CQ ring size
to a specific size, we ensure that the CQ size is at least that of the
SQ ring size. But in doing so, we compare the already rounded up to power
of two SQ size to the as-of yet unrounded CQ size. This means that if an
application passes in non power of two sizes, we can return -EINVAL when
the final value would've been fine. As an example, an application passing
in 100/100 for sq/cq size should end up with 128 for both. But since we
round the SQ size first, we compare the CQ size of 100 to 128, and return
-EINVAL as that is too small.

Cc: stable@vger.kernel.org
Fixes: 33a107f0 ("io_uring: allow application controlled CQ ring size")
Reported-by: default avatarDan Melnic <dmm@fb.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 9a472ef7
...@@ -9226,6 +9226,7 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p, ...@@ -9226,6 +9226,7 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p,
* to a power-of-two, if it isn't already. We do NOT impose * to a power-of-two, if it isn't already. We do NOT impose
* any cq vs sq ring sizing. * any cq vs sq ring sizing.
*/ */
p->cq_entries = roundup_pow_of_two(p->cq_entries);
if (p->cq_entries < p->sq_entries) if (p->cq_entries < p->sq_entries)
return -EINVAL; return -EINVAL;
if (p->cq_entries > IORING_MAX_CQ_ENTRIES) { if (p->cq_entries > IORING_MAX_CQ_ENTRIES) {
...@@ -9233,7 +9234,6 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p, ...@@ -9233,7 +9234,6 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p,
return -EINVAL; return -EINVAL;
p->cq_entries = IORING_MAX_CQ_ENTRIES; p->cq_entries = IORING_MAX_CQ_ENTRIES;
} }
p->cq_entries = roundup_pow_of_two(p->cq_entries);
} else { } else {
p->cq_entries = 2 * p->sq_entries; p->cq_entries = 2 * p->sq_entries;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment