public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Hao Xu <[email protected]>, Jens Axboe <[email protected]>
Cc: [email protected], Joseph Qi <[email protected]>
Subject: Re: [PATCH v3] io_uring: fix possible deadlock in io_uring_poll
Date: Tue, 9 Feb 2021 23:30:04 +0000	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

On 05/02/2021 12:58, Pavel Begunkov wrote:
> On 05/02/2021 08:34, Hao Xu wrote:
>> This might happen if we do epoll_wait on a uring fd while reading/writing
>> the former epoll fd in a sqe in the former uring instance.
>> So let's don't flush cqring overflow list, just do a simple check.
> 
> I haven't tested it but tried out identical before.
> 
> Reviewed-by: Pavel Begunkov <[email protected]>
> Cc: [email protected] # 5.5+

Don't see it queued, so up, in case it was forgotten

> 
>>
>> Reported-by: Abaci <[email protected]>
>> Fixes: 6c503150ae33 ("io_uring: patch up IOPOLL overflow_flush sync")
>> Signed-off-by: Hao Xu <[email protected]>
>> ---
>>  fs/io_uring.c | 17 +++++++++++++++--
>>  1 file changed, 15 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/io_uring.c b/fs/io_uring.c
>> index 38c6cbe1ab38..5f42ad6f2155 100644
>> --- a/fs/io_uring.c
>> +++ b/fs/io_uring.c
>> @@ -8718,8 +8718,21 @@ static __poll_t io_uring_poll(struct file *file, poll_table *wait)
>>  	smp_rmb();
>>  	if (!io_sqring_full(ctx))
>>  		mask |= EPOLLOUT | EPOLLWRNORM;
>> -	io_cqring_overflow_flush(ctx, false, NULL, NULL);
>> -	if (io_cqring_events(ctx))
>> +
>> +	/*
>> +	 * Don't flush cqring overflow list here, just do a simple check.
>> +	 * Otherwise there could possible be ABBA deadlock:
>> +	 *      CPU0                    CPU1
>> +	 *      ----                    ----
>> +	 * lock(&ctx->uring_lock);
>> +	 *                              lock(&ep->mtx);
>> +	 *                              lock(&ctx->uring_lock);
>> +	 * lock(&ep->mtx);
>> +	 *
>> +	 * Users may get EPOLLIN meanwhile seeing nothing in cqring, this
>> +	 * pushs them to do the flush.
>> +	 */
>> +	if (io_cqring_events(ctx) || test_bit(0, &ctx->cq_check_overflow))
>>  		mask |= EPOLLIN | EPOLLRDNORM;
>>  
>>  	return mask;
>>
> 

-- 
Pavel Begunkov

  reply	other threads:[~2021-02-10  0:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05  7:49 [PATCH v2] io_uring: fix possible deadlock in io_uring_poll Hao Xu
2021-02-05  8:34 ` [PATCH v3] " Hao Xu
2021-02-05 12:58   ` Pavel Begunkov
2021-02-09 23:30     ` Pavel Begunkov [this message]
2021-02-10  2:27   ` Jens Axboe

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] \
    /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