public inbox for [email protected]
 help / color / mirror / Atom feed
From: Jens Axboe <[email protected]>
To: Pavel Begunkov <[email protected]>,
	Hao Xu <[email protected]>
Cc: [email protected], Joseph Qi <[email protected]>
Subject: Re: [PATCH 1/2] io_uring: add uring_lock as an argument to io_sqe_files_unregister()
Date: Thu, 4 Feb 2021 07:49:21 -0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

On 2/4/21 4:11 AM, Pavel Begunkov wrote:
> On 04/02/2021 03:34, Hao Xu wrote:
>> 在 2021/2/4 上午12:33, Pavel Begunkov 写道:
>>> On 03/02/2021 14:57, Hao Xu wrote:
>>>> 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.
>>>
>>> It's ugly, just take the lock and kill the patch. There can't be any
>>> contention during io_ring_ctx_free anyway.
>> Hi Pavel, I don't get it, do you mean this patch isn't needed, and we can just unlock(&uring_lock) before io_run_task_work_sig() and lock(&uring_lock) after it? I knew there won't be contention during io_ring_ctx_free that's why there is no uring_lock in it.
>> I tried to just do unlock(&uring_lock) before io_run_task_sig() without if(locked) check, it reports something like "there are unpaired mutex lock/unlock" since we cannot just unlock if it's from io_ring_ctx_free.
> 
> 
> The ugly part is @locked. I know that there is already similar stuff
> around, but I may go long why and how much I don't like it.
> 
> io_ring_ctx_free()
> {
>     ...
>     lock(uring_lock);
>     files_unregister();
>     unlock(uring_lock);
>     ...
> }
> 
> With this you'll always have the mutex locked in unregister, so
> can drop it unconditionally (if that will ever be needed). It's
> also cleaner from the synchronisation perspective.

Yes that's a much better approach - passing around a 'locked' flag
is not very pretty, and the fewer we have of those the better.

-- 
Jens Axboe


  reply	other threads:[~2021-02-04 14:51 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 ` [PATCH 1/2] io_uring: add uring_lock as an argument to io_sqe_files_unregister() Hao Xu
2021-02-03 16:33   ` Pavel Begunkov
2021-02-04  3:34     ` Hao Xu
2021-02-04 11:11       ` Pavel Begunkov
2021-02-04 14:49         ` Jens Axboe [this message]
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 \
    [email protected] \
    [email protected] \
    [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