IO-Uring Archive on lore.kernel.org
 help / color / 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
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 index

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

IO-Uring Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/io-uring/0 io-uring/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 io-uring io-uring/ https://lore.kernel.org/io-uring \
		io-uring@vger.kernel.org
	public-inbox-index io-uring

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.io-uring


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git