From: Pavel Begunkov asml.silence@gmail.com
mainline inclusion from mainline-5.9-rc1 commit 9b5f7bd93272689ec8dc2cfd40a812265c23414e category: feature bugzilla: https://bugzilla.openeuler.org/show_bug.cgi?id=27 CVE: NA ---------------------------
Generally, it's better to return a value directly than having out parameter. It's cleaner and saves from some kinds of ugly bugs. May also be faster.
Return next request from io_req_find_next() and friends directly instead of passing out parameter.
Signed-off-by: Pavel Begunkov asml.silence@gmail.com Signed-off-by: Jens Axboe axboe@kernel.dk
Conflicts: fs/io_uring.c [4ae6dbd683860 ("io_uring: fix lockup in io_fail_links()") and 6a0af224c213 ("io_uring: don't put a poll req under spinlock") seems same. and we has adopt 4ae6dbd683860, no need to include 6a0af224c213.]
Signed-off-by: yangerkun yangerkun@huawei.com Reviewed-by: zhangyi (F) yi.zhang@huawei.com Signed-off-by: Cheng Jian cj.chengjian@huawei.com --- fs/io_uring.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c index c7cd6a2539f1..289423385746 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1659,7 +1659,7 @@ static void io_kill_linked_timeout(struct io_kiocb *req) io_cqring_ev_posted(ctx); }
-static void io_req_link_next(struct io_kiocb *req, struct io_kiocb **nxtptr) +static struct io_kiocb *io_req_link_next(struct io_kiocb *req) { struct io_kiocb *nxt;
@@ -1669,13 +1669,13 @@ static void io_req_link_next(struct io_kiocb *req, struct io_kiocb **nxtptr) * safe side. */ if (unlikely(list_empty(&req->link_list))) - return; + return NULL;
nxt = list_first_entry(&req->link_list, struct io_kiocb, link_list); list_del_init(&req->link_list); if (!list_empty(&nxt->link_list)) nxt->flags |= REQ_F_LINK_HEAD; - *nxtptr = nxt; + return nxt; }
/* @@ -1719,10 +1719,10 @@ static void io_fail_links(struct io_kiocb *req) io_cqring_ev_posted(ctx); }
-static void io_req_find_next(struct io_kiocb *req, struct io_kiocb **nxt) +static struct io_kiocb *io_req_find_next(struct io_kiocb *req) { if (likely(!(req->flags & REQ_F_LINK_HEAD))) - return; + return NULL; req->flags &= ~REQ_F_LINK_HEAD;
if (req->flags & REQ_F_LINK_TIMEOUT) @@ -1734,10 +1734,10 @@ static void io_req_find_next(struct io_kiocb *req, struct io_kiocb **nxt) * dependencies to the next request. In case of failure, fail the rest * of the chain. */ - if (req->flags & REQ_F_FAIL_LINK) - io_fail_links(req); - else - io_req_link_next(req, nxt); + if (likely(!(req->flags & REQ_F_FAIL_LINK))) + return io_req_link_next(req); + io_fail_links(req); + return NULL; }
static void __io_req_task_cancel(struct io_kiocb *req, int error) @@ -1804,9 +1804,7 @@ static void io_req_task_queue(struct io_kiocb *req)
static void io_queue_next(struct io_kiocb *req) { - struct io_kiocb *nxt = NULL; - - io_req_find_next(req, &nxt); + struct io_kiocb *nxt = io_req_find_next(req);
if (nxt) io_req_task_queue(nxt); @@ -1857,13 +1855,15 @@ static void io_req_free_batch(struct req_batch *rb, struct io_kiocb *req) * Drop reference to request, return next in chain (if there is one) if this * was the last reference to this request. */ -__attribute__((nonnull)) -static void io_put_req_find_next(struct io_kiocb *req, struct io_kiocb **nxtptr) +static struct io_kiocb *io_put_req_find_next(struct io_kiocb *req) { + struct io_kiocb *nxt = NULL; + if (refcount_dec_and_test(&req->refs)) { - io_req_find_next(req, nxtptr); + nxt = io_req_find_next(req); __io_free_req(req); } + return nxt; }
static void io_put_req(struct io_kiocb *req) @@ -1884,7 +1884,7 @@ static struct io_wq_work *io_steal_work(struct io_kiocb *req) if (refcount_read(&req->refs) != 1) return NULL;
- io_req_find_next(req, &nxt); + nxt = io_req_find_next(req); if (!nxt) return NULL;
@@ -4403,7 +4403,7 @@ static void io_poll_task_handler(struct io_kiocb *req, struct io_kiocb **nxt) io_poll_complete(req, req->result, 0); spin_unlock_irq(&ctx->completion_lock);
- io_put_req_find_next(req, nxt); + *nxt = io_put_req_find_next(req); io_cqring_ev_posted(ctx); }
@@ -5841,9 +5841,8 @@ static void __io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe, }
err: - nxt = NULL; /* drop submission reference */ - io_put_req_find_next(req, &nxt); + nxt = io_put_req_find_next(req);
if (linked_timeout) { if (!ret)