summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2021-02-07 23:32:17 +0000
committerJens Axboe <axboe@kernel.dk>2021-02-08 08:25:57 -0700
commitbe648cf24cf3da1e987349e87e25d2f913721ac0 (patch)
treee62fccfad262261f6838661512b5bf649d105307
parentb4fea6b86d6555ea22ebeff16b7922f5a0c7852a (diff)
downloadliburing-be648cf24cf3da1e987349e87e25d2f913721ac0.tar.gz
liburing-be648cf24cf3da1e987349e87e25d2f913721ac0.tar.bz2
src/queue: don't loop when don't enter
_io_uring_get_cqe() can live-lock in some cases, always return if we're not going to do __sys_io_uring_enter(). Reported-by: Victor Stewart <v@nametag.social> Suggested-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--src/queue.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/queue.c b/src/queue.c
index be461c6..8c394dd 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -89,12 +89,13 @@ static int _io_uring_get_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_pt
{
struct io_uring_cqe *cqe = NULL;
const int to_wait = data->wait_nr;
- int ret = 0, err;
+ int err;
do {
bool cq_overflow_flush = false;
unsigned flags = 0;
unsigned nr_available;
+ int ret;
err = __io_uring_peek_cqe(ring, &cqe, &nr_available);
if (err)
@@ -110,11 +111,13 @@ static int _io_uring_get_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_pt
flags = IORING_ENTER_GETEVENTS | data->get_flags;
if (data->submit)
sq_ring_needs_enter(ring, &flags);
- if (data->wait_nr > nr_available || data->submit ||
- cq_overflow_flush)
- ret = __sys_io_uring_enter2(ring->ring_fd, data->submit,
- data->wait_nr, flags, data->arg,
- data->sz);
+ if (data->wait_nr <= nr_available && !data->submit &&
+ !cq_overflow_flush)
+ break;
+
+ ret = __sys_io_uring_enter2(ring->ring_fd, data->submit,
+ data->wait_nr, flags, data->arg,
+ data->sz);
if (ret < 0) {
err = -errno;
break;