public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Cc: [email protected]
Subject: Re: [PATCH 5.10 2/5] io_uring: fix racy IOPOLL completions
Date: Mon, 7 Dec 2020 18:31:47 +0000	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <3a8d4b11f6cbb28c5067fd77ba35c2995f4658be.1607293068.git.asml.silence@gmail.com>

On 06/12/2020 22:22, Pavel Begunkov wrote:
> IOPOLL allows buffer remove/provide requests, but they doesn't
> synchronise by rules of IOPOLL, namely it have to hold uring_lock.
> 
> Cc: <[email protected]> # 5.7+
> Signed-off-by: Pavel Begunkov <[email protected]>
> ---
>  fs/io_uring.c | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index c895a306f919..4fac02ea5f4c 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -3948,11 +3948,17 @@ static int io_remove_buffers(struct io_kiocb *req, bool force_nonblock,
>  	head = idr_find(&ctx->io_buffer_idr, p->bgid);
>  	if (head)
>  		ret = __io_remove_buffers(ctx, head, p->bgid, p->nbufs);
> -
> -	io_ring_submit_lock(ctx, !force_nonblock);

Here should be unlock(), not a second lock(). I didn't notice
first, but the patch fixes it. maybe for 5.10?

>  	if (ret < 0)
>  		req_set_fail_links(req);
> -	__io_req_complete(req, ret, 0, cs);
> +
> +	/* need to hold the lock to complete IOPOLL requests */
> +	if (ctx->flags & IORING_SETUP_IOPOLL) {
> +		__io_req_complete(req, ret, 0, cs);
> +		io_ring_submit_unlock(ctx, !force_nonblock);
> +	} else {
> +		io_ring_submit_unlock(ctx, !force_nonblock);
> +		__io_req_complete(req, ret, 0, cs);
> +	}
>  	return 0;
>  }


-- 
Pavel Begunkov

  reply	other threads:[~2020-12-07 18:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-06 22:22 [PATCH 5.10 0/5] iopoll fixes Pavel Begunkov
2020-12-06 22:22 ` [PATCH 5.10 1/5] io_uring: always let io_iopoll_complete() complete polled io Pavel Begunkov
2020-12-07 16:28   ` Jens Axboe
2020-12-08 19:12     ` Pavel Begunkov
2020-12-08 19:17       ` Jens Axboe
2020-12-08 19:24         ` Pavel Begunkov
2020-12-08 21:10           ` Jens Axboe
2020-12-09 20:17             ` Pavel Begunkov
2020-12-10 17:38               ` Pavel Begunkov
2020-12-06 22:22 ` [PATCH 5.10 2/5] io_uring: fix racy IOPOLL completions Pavel Begunkov
2020-12-07 18:31   ` Pavel Begunkov [this message]
2020-12-06 22:22 ` [PATCH 5.10 3/5] io_uring: fix racy IOPOLL flush overflow Pavel Begunkov
2020-12-06 22:22 ` [PATCH 5.10 4/5] io_uring: fix io_cqring_events()'s noflush Pavel Begunkov
2020-12-06 22:22 ` [PATCH 5.10 5/5] io_uring: fix mis-seting personality's creds Pavel Begunkov
2020-12-07 15:05 ` [PATCH 5.10 0/5] iopoll fixes Jens Axboe
2020-12-07 15:24   ` Pavel Begunkov
2020-12-07 15:28     ` 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] \
    /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