From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Cc: Victor Stewart <[email protected]>
Subject: [PATCH liburing 3/3] src/queue: don't loop when don't enter
Date: Sun, 7 Feb 2021 23:32:17 +0000 [thread overview]
Message-ID: <39bc4096ded4d4d0e8f8059bff52a51d16617213.1612740655.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
_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 <[email protected]>
Suggested-by: Jens Axboe <[email protected]>
Signed-off-by: Pavel Begunkov <[email protected]>
---
src/queue.c | 15 +++++++++------
1 file 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;
--
2.24.0
next prev parent reply other threads:[~2021-02-07 23:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-07 23:32 [PATCH liburing 0/3] fix _io_uring_get_cqe() Pavel Begunkov
2021-02-07 23:32 ` [PATCH liburing 1/3] src/queue: don't wait for less than expected Pavel Begunkov
2021-02-07 23:32 ` [PATCH liburing 2/3] src/queue: clean _io_uring_get_cqe() err handling Pavel Begunkov
2021-02-07 23:32 ` Pavel Begunkov [this message]
2021-02-08 15:26 ` [PATCH liburing 0/3] fix _io_uring_get_cqe() Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=39bc4096ded4d4d0e8f8059bff52a51d16617213.1612740655.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox