Skip to content

Commit 31bff9a

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix racy IOPOLL completions
IOPOLL allows buffer remove/provide requests, but they doesn't synchronise by rules of IOPOLL, namely it have to hold uring_lock. Cc: <[email protected]> # 5.7+ Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent dad1b12 commit 31bff9a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

fs/io_uring.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4152,11 +4152,17 @@ static int io_remove_buffers(struct io_kiocb *req, bool force_nonblock,
41524152
head = idr_find(&ctx->io_buffer_idr, p->bgid);
41534153
if (head)
41544154
ret = __io_remove_buffers(ctx, head, p->bgid, p->nbufs);
4155-
4156-
io_ring_submit_lock(ctx, !force_nonblock);
41574155
if (ret < 0)
41584156
req_set_fail_links(req);
4159-
__io_req_complete(req, ret, 0, cs);
4157+
4158+
/* need to hold the lock to complete IOPOLL requests */
4159+
if (ctx->flags & IORING_SETUP_IOPOLL) {
4160+
__io_req_complete(req, ret, 0, cs);
4161+
io_ring_submit_unlock(ctx, !force_nonblock);
4162+
} else {
4163+
io_ring_submit_unlock(ctx, !force_nonblock);
4164+
__io_req_complete(req, ret, 0, cs);
4165+
}
41604166
return 0;
41614167
}
41624168

@@ -4241,10 +4247,17 @@ static int io_provide_buffers(struct io_kiocb *req, bool force_nonblock,
42414247
}
42424248
}
42434249
out:
4244-
io_ring_submit_unlock(ctx, !force_nonblock);
42454250
if (ret < 0)
42464251
req_set_fail_links(req);
4247-
__io_req_complete(req, ret, 0, cs);
4252+
4253+
/* need to hold the lock to complete IOPOLL requests */
4254+
if (ctx->flags & IORING_SETUP_IOPOLL) {
4255+
__io_req_complete(req, ret, 0, cs);
4256+
io_ring_submit_unlock(ctx, !force_nonblock);
4257+
} else {
4258+
io_ring_submit_unlock(ctx, !force_nonblock);
4259+
__io_req_complete(req, ret, 0, cs);
4260+
}
42484261
return 0;
42494262
}
42504263

0 commit comments

Comments
 (0)