All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hao Xu <haoxu@linux.alibaba.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: io-uring@vger.kernel.org, Pavel Begunkov <asml.silence@gmail.com>,
	Joseph Qi <joseph.qi@linux.alibaba.com>
Subject: [PATCH 1/2] io_uring: add uring_lock as an argument to io_sqe_files_unregister()
Date: Wed,  3 Feb 2021 22:57:55 +0800	[thread overview]
Message-ID: <1612364276-26847-2-git-send-email-haoxu@linux.alibaba.com> (raw)
In-Reply-To: <1612364276-26847-1-git-send-email-haoxu@linux.alibaba.com>

io_sqe_files_unregister is currently called from several places:
    - syscall io_uring_register (with uring_lock)
    - io_ring_ctx_wait_and_kill() (without uring_lock)

There is a AA type deadlock in io_sqe_files_unregister(), thus we need
to know if we hold uring_lock in io_sqe_files_unregister() to fix the
issue.

Signed-off-by: Hao Xu <haoxu@linux.alibaba.com>
---
 fs/io_uring.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 38c6cbe1ab38..efb6d02fea6f 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7339,7 +7339,7 @@ static void io_sqe_files_set_node(struct fixed_file_data *file_data,
 	percpu_ref_get(&file_data->refs);
 }
 
-static int io_sqe_files_unregister(struct io_ring_ctx *ctx)
+static int io_sqe_files_unregister(struct io_ring_ctx *ctx, bool locked)
 {
 	struct fixed_file_data *data = ctx->file_data;
 	struct fixed_file_ref_node *backup_node, *ref_node = NULL;
@@ -7872,13 +7872,13 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
 
 	ret = io_sqe_files_scm(ctx);
 	if (ret) {
-		io_sqe_files_unregister(ctx);
+		io_sqe_files_unregister(ctx, true);
 		return ret;
 	}
 
 	ref_node = alloc_fixed_file_ref_node(ctx);
 	if (!ref_node) {
-		io_sqe_files_unregister(ctx);
+		io_sqe_files_unregister(ctx, true);
 		return -ENOMEM;
 	}
 
@@ -8682,7 +8682,7 @@ static void io_ring_ctx_free(struct io_ring_ctx *ctx)
 		css_put(ctx->sqo_blkcg_css);
 #endif
 
-	io_sqe_files_unregister(ctx);
+	io_sqe_files_unregister(ctx, false);
 	io_eventfd_unregister(ctx);
 	io_destroy_buffers(ctx);
 	idr_destroy(&ctx->personality_idr);
@@ -10065,7 +10065,7 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
 		ret = -EINVAL;
 		if (arg || nr_args)
 			break;
-		ret = io_sqe_files_unregister(ctx);
+		ret = io_sqe_files_unregister(ctx, true);
 		break;
 	case IORING_REGISTER_FILES_UPDATE:
 		ret = io_sqe_files_update(ctx, arg, nr_args);
-- 
1.8.3.1


  reply	other threads:[~2021-02-03 15:01 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 14:57 [PATCH 0/2] fix deadlock in __io_req_task_submit() Hao Xu
2021-02-03 14:57 ` Hao Xu [this message]
2021-02-03 16:33   ` [PATCH 1/2] io_uring: add uring_lock as an argument to io_sqe_files_unregister() Pavel Begunkov
2021-02-04  3:34     ` Hao Xu
2021-02-04 11:11       ` Pavel Begunkov
2021-02-04 14:49         ` Jens Axboe
2021-02-03 14:57 ` [PATCH 2/2] io_uring: don't hold uring_lock when calling io_run_task_work* Hao Xu
2021-02-03 16:35   ` Pavel Begunkov
2021-02-03 16:45     ` Pavel Begunkov
2021-02-04  3:25       ` Hao Xu
2021-02-04 11:17         ` Pavel Begunkov
2021-02-04 15:26           ` Pavel Begunkov
2021-02-05  9:57             ` Hao Xu
2021-02-05 10:18               ` Pavel Begunkov
2021-02-06 11:34                 ` Hao Xu
2021-02-07 17:16                   ` Pavel Begunkov
2021-02-06 16:21                 ` Hao Xu
2021-02-11 13:30                 ` Hao Xu
2021-02-05 10:03       ` Hao Xu
2021-02-04 11:33   ` Pavel Begunkov

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=1612364276-26847-2-git-send-email-haoxu@linux.alibaba.com \
    --to=haoxu@linux.alibaba.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=joseph.qi@linux.alibaba.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.