io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: Hao Xu <haoxu@linux.alibaba.com>,
	io-uring <io-uring@vger.kernel.org>, Jens Axboe <axboe@kernel.dk>
Subject: Re: Queston about io_uring_flush
Date: Thu, 4 Feb 2021 11:00:16 +0000	[thread overview]
Message-ID: <51499dcc-5991-e177-98c4-8cc8a909da70@gmail.com> (raw)
In-Reply-To: <63d16aae-1ca7-8939-1c8a-89c600be8462@linux.alibaba.com>

On 04/02/2021 09:31, Hao Xu wrote:
> Hi all,
> Sorry for disturb all of you. Here comes my question.
> When we close a uring file, we go into io_uring_flush(),
> there is codes at the end:
> 
> if (!(ctx->flags & IORING_SETUP_SQPOLL) || ctx->sqo_task == current)
>    io_uring_del_task_file(file);
> 
> My understanding, this is to delete the ctx(associated with the uring
> file) from current->io_uring->xa.
> I'm thinking of this scenario: the task to close uring file is not the
> one which created the uring file.
> Then it doesn't make sense to delete the uring file from current->io_uring->xa. It should be "delete uring file from
> ctx->sqo_task->io_uring->xa" instead.

1. It's not only about created or not, look for
io_uring_add_task_file() call sites.

2. io_uring->xa is basically a map from task to used by it urings.
Every user task should clean only its own context (SQPOLL task is
a bit different), it'll be hell bunch of races otherwise.

3. If happens that it's closed by a task that has nothing to do
with this ctx, then it won't find anything in its
task->io_uring->xa, and so won't delete anything, and that's ok.
io_uring->xa of sqo_task will be cleaned by sqo_task, either
on another close() or on exit() (see io_uring_files_cancel).

4. There is a bunch of cases where that scheme doesn't behave
nice, but at least should not leak/fault when all related tasks
are killed.

-- 
Pavel Begunkov

  reply	other threads:[~2021-02-04 11:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-04  9:31 Queston about io_uring_flush Hao Xu
2021-02-04 11:00 ` Pavel Begunkov [this message]
2021-02-05  7:21   ` Hao Xu
2021-02-05  9:56     ` 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=51499dcc-5991-e177-98c4-8cc8a909da70@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=haoxu@linux.alibaba.com \
    --cc=io-uring@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).