IO-Uring Archive on lore.kernel.org
 help / color / Atom feed
* Question about fileset unregister and update codes
@ 2020-03-25 13:55 Xiaoguang Wang
  2020-05-11 11:09 ` Xiaoguang Wang
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaoguang Wang @ 2020-03-25 13:55 UTC (permalink / raw)
  To: io-uring; +Cc: axboe, joseph qi

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Question about fileset unregister and update codes
  2020-03-25 13:55 Question about fileset unregister and update codes Xiaoguang Wang
@ 2020-05-11 11:09 ` Xiaoguang Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Xiaoguang Wang @ 2020-05-11 11:09 UTC (permalink / raw)
  To: axboe; +Cc: joseph qi, io-uring

hi,

Could you please have a look at this mail? Thanks.

Regards,
Xiaoguang Wang

> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-25 13:55 Question about fileset unregister and update codes Xiaoguang Wang
2020-05-11 11:09 ` Xiaoguang Wang

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