io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
To: io-uring@vger.kernel.org
Cc: "axboe@kernel.dk" <axboe@kernel.dk>,
	joseph qi <joseph.qi@linux.alibaba.com>
Subject: Question about fileset unregister and update codes
Date: Wed, 25 Mar 2020 21:55:54 +0800	[thread overview]
Message-ID: <64638b5f-401e-5cf4-23d9-0a31119d1b9c@linux.alibaba.com> (raw)

hi,

Look at below function:
static bool io_register_op_must_quiesce(int op)
{
	switch (op) {
	case IORING_UNREGISTER_FILES:
	case IORING_REGISTER_FILES_UPDATE:
	case IORING_REGISTER_PROBE:
	case IORING_REGISTER_PERSONALITY:
	case IORING_UNREGISTER_PERSONALITY:
		return false;
	default:
		return true;
	}
}

IORING_REGISTER_FILES will quiesces the ctx, but IORING_UNREGISTER_FILES
and IORING_REGISTER_FILES_UPDATE won't, so I wonder how userspace applications
can sure when they can unregister or update the registered fileset.
Imagine below application behaviour:
      ThreadA                     |      ThreadB
                                  |
     1, register a file           |     while (1) {
     2, prepare a batch of sqes   |         wait a cqe and handle this cqe.
     3, submit prepared sqes      |     }
     4, unregister or update file |
                                  |

If IORING_SETUP_SQPOLL is not enabled, I think step4 is safe, because step3
will ensure that all sqes will be prepared by io_req_set_file(), then corresponding
struct file will be resolved and ctx->file_data->refs will be increased, we know
unless requst is completed, struct file will not be put, finally we know step4
is safe.

But if IORING_SETUP_SQPOLL is enabled, step3 will complete quickly, if kernel
thread io_sq_thread submit sqes before step4, everything is ok, but if step4
starts to run, holding uring_lock, later io_sq_thread starts to handle sqes and
all previously submitted sqes will be returned with EBADF.

I'm not sure whether should make application ensure that all sqes against registered
file to complete, then app can unregister or update fileset, if so, I think it'll
introduce extra programming overhead to programmer.

Or if IORING_SETUP_SQPOLL is enabled, we call io_submit_sqes in unregister/update codes,
then applications will not need to worry about above race.

Regards,
Xiaoguang Wang

             reply	other threads:[~2020-03-25 13:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25 13:55 Xiaoguang Wang [this message]
2020-05-11 11:09 ` Question about fileset unregister and update codes Xiaoguang Wang

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=64638b5f-401e-5cf4-23d9-0a31119d1b9c@linux.alibaba.com \
    --to=xiaoguang.wang@linux.alibaba.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 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).