From: Pavel Begunkov Date: Sat, 25 Jan 2020 19:34:01 +0000 (+0300) Subject: io_uring: fix refcounting with batched allocations at OOM X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=9466f43741bc08edd7b1bee642dd6f5561091634;p=linux.git io_uring: fix refcounting with batched allocations at OOM In case of out of memory the second argument of percpu_ref_put_many() in io_submit_sqes() may evaluate into "nr - (-EAGAIN)", that is clearly wrong. Fixes: 2b85edfc0c90 ("io_uring: batch getting pcpu references") Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe --- diff --git a/fs/io_uring.c b/fs/io_uring.c index a700ee5fc89d6..1dd20305c6644 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -4830,8 +4830,11 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr, break; } - if (submitted != nr) - percpu_ref_put_many(&ctx->refs, nr - submitted); + if (unlikely(submitted != nr)) { + int ref_used = (submitted == -EAGAIN) ? 0 : submitted; + + percpu_ref_put_many(&ctx->refs, nr - ref_used); + } if (link) io_queue_link_head(link); if (statep)