public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, Ming Lei <[email protected]>,
	[email protected], [email protected]
Cc: David Howells <[email protected]>,
	Chengming Zhou <[email protected]>
Subject: Re: [PATCH V3] io_uring: fix IO hang in io_wq_put_and_exit from do_exit()
Date: Fri, 8 Sep 2023 16:46:15 +0100	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

On 9/8/23 14:49, Jens Axboe wrote:
> On 9/8/23 3:30 AM, Ming Lei wrote:
>> diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
>> index ad636954abae..95a3d31a1ef1 100644
>> --- a/io_uring/io_uring.c
>> +++ b/io_uring/io_uring.c
>> @@ -1930,6 +1930,10 @@ void io_wq_submit_work(struct io_wq_work *work)
>>   		}
>>   	}
>>   
>> +	/* It is fragile to block POLLED IO, so switch to NON_BLOCK */
>> +	if ((req->ctx->flags & IORING_SETUP_IOPOLL) && def->iopoll_queue)
>> +		issue_flags |= IO_URING_F_NONBLOCK;
>> +
> 
> I think this comment deserves to be more descriptive. Normally we
> absolutely cannot block for polled IO, it's only OK here because io-wq
> is the issuer and not necessarily the poller of it. That generally falls
> upon the original issuer to poll these requests.
> 
> I think this should be a separate commit, coming before the main fix
> which is below.
> 
>> @@ -3363,6 +3367,12 @@ __cold void io_uring_cancel_generic(bool cancel_all, struct io_sq_data *sqd)
>>   		finish_wait(&tctx->wait, &wait);
>>   	} while (1);
>>   
>> +	/*
>> +	 * Reap events from each ctx, otherwise these requests may take
>> +	 * resources and prevent other contexts from being moved on.
>> +	 */
>> +	xa_for_each(&tctx->xa, index, node)
>> +		io_iopoll_try_reap_events(node->ctx);
> 
> The main issue here is that if someone isn't polling for them, then we
> get to wait for a timeout before they complete. This can delay exit, for
> example, as we're now just waiting 30 seconds (or whatever the timeout
> is on the underlying device) for them to get timed out before exit can
> finish.

Ok, our case is that userspace crashes and doesn't poll for its IO.
How would that block io-wq termination? We send a signal and workers
should exit, either by queueing up the request for iopoll (and then
we queue it into the io_uring iopoll list and the worker immediately
returns back and presumably exits), or it fails because of the signal
and returns back.

That should kill all io-wq and make exit go forward. Then the io_uring
file will be destroyed and the ring exit work will be polling via

io_ring_exit_work();
-- io_uring_try_cancel_requests();
   -- io_iopoll_try_reap_events();

What I'm missing? Does the blocking change make io-wq iopolling
completions inside the block? Was it by any chance with the recent
"do_exit() waiting for ring destruction" patches?


-- 
Pavel Begunkov

  parent reply	other threads:[~2023-09-08 15:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-08  9:30 [PATCH V3] io_uring: fix IO hang in io_wq_put_and_exit from do_exit() Ming Lei
2023-09-08 13:49 ` Jens Axboe
2023-09-08 14:34   ` Ming Lei
2023-09-08 14:44     ` Jens Axboe
2023-09-08 15:25       ` Ming Lei
2023-09-15  7:04         ` Jason Wang
2023-09-25 21:17           ` Stefan Hajnoczi
2023-09-26  1:28             ` Ming Lei
2023-09-26 14:55               ` Stefan Hajnoczi
2023-09-08 15:46   ` Pavel Begunkov [this message]
2023-09-09  1:43     ` Ming Lei
2023-09-13 12:53       ` 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] \
    [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