public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>,
	[email protected], [email protected]
Subject: Re: [PATCH 1/3] io_uring: pass sqe for link head
Date: Thu, 6 Feb 2020 00:39:19 +0300	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <c9654d6a79898d5f8aa8b9dabcb76d9f23faa149.1580928112.git.asml.silence@gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 3584 bytes --]

On 05/02/2020 22:07, Pavel Begunkov wrote:
> Save an sqe for a head of a link, so it doesn't go through switch in
> io_req_defer_prep() nor allocating an async context in advance.
> 
> Also, it's fixes potenial memleak for double-preparing head requests.
> E.g. prep in io_submit_sqe() and then prep in io_req_defer(),
> which leaks iovec for vectored read/writes.

Looking through -rc1, remembered that Jens already fixed this. So, this may be
striked out.


> 
> Signed-off-by: Pavel Begunkov <[email protected]>
> ---
>  fs/io_uring.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index f00c2c9c67c0..e18056af5672 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -4721,20 +4721,22 @@ static void io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe)
>  	}
>  }
>  
> -static inline void io_queue_link_head(struct io_kiocb *req)
> +static inline void io_queue_link_head(struct io_kiocb *req,
> +				      const struct io_uring_sqe *sqe)
>  {
>  	if (unlikely(req->flags & REQ_F_FAIL_LINK)) {
>  		io_cqring_add_event(req, -ECANCELED);
>  		io_double_put_req(req);
>  	} else
> -		io_queue_sqe(req, NULL);
> +		io_queue_sqe(req, sqe);
>  }
>  
>  #define SQE_VALID_FLAGS	(IOSQE_FIXED_FILE|IOSQE_IO_DRAIN|IOSQE_IO_LINK|	\
>  				IOSQE_IO_HARDLINK | IOSQE_ASYNC)
>  
>  static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
> -			  struct io_submit_state *state, struct io_kiocb **link)
> +			  struct io_submit_state *state, struct io_kiocb **link,
> +			  const struct io_uring_sqe **link_sqe)
>  {
>  	const struct cred *old_creds = NULL;
>  	struct io_ring_ctx *ctx = req->ctx;
> @@ -4812,7 +4814,7 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
>  
>  		/* last request of a link, enqueue the link */
>  		if (!(sqe_flags & (IOSQE_IO_LINK|IOSQE_IO_HARDLINK))) {
> -			io_queue_link_head(head);
> +			io_queue_link_head(head, *link_sqe);
>  			*link = NULL;
>  		}
>  	} else {
> @@ -4823,10 +4825,8 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
>  		if (sqe_flags & (IOSQE_IO_LINK|IOSQE_IO_HARDLINK)) {
>  			req->flags |= REQ_F_LINK;
>  			INIT_LIST_HEAD(&req->link_list);
> -			ret = io_req_defer_prep(req, sqe);
> -			if (ret)
> -				req->flags |= REQ_F_FAIL_LINK;
>  			*link = req;
> +			*link_sqe = sqe;
>  		} else {
>  			io_queue_sqe(req, sqe);
>  		}
> @@ -4924,6 +4924,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
>  	struct io_kiocb *link = NULL;
>  	int i, submitted = 0;
>  	bool mm_fault = false;
> +	const struct io_uring_sqe *link_sqe = NULL;
>  
>  	/* if we have a backlog and couldn't flush it all, return BUSY */
>  	if (test_bit(0, &ctx->sq_check_overflow)) {
> @@ -4983,7 +4984,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
>  		req->needs_fixed_file = async;
>  		trace_io_uring_submit_sqe(ctx, req->opcode, req->user_data,
>  						true, async);
> -		if (!io_submit_sqe(req, sqe, statep, &link))
> +		if (!io_submit_sqe(req, sqe, statep, &link, &link_sqe))
>  			break;
>  	}
>  
> @@ -4993,7 +4994,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
>  		percpu_ref_put_many(&ctx->refs, nr - ref_used);
>  	}
>  	if (link)
> -		io_queue_link_head(link);
> +		io_queue_link_head(link, link_sqe);
>  	if (statep)
>  		io_submit_state_end(&state);
>  
> 

-- 
Pavel Begunkov


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2020-02-05 21:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-05 19:07 [PATCH 0/3] io_uring: clean wq path Pavel Begunkov
2020-02-05 19:07 ` [PATCH 1/3] io_uring: pass sqe for link head Pavel Begunkov
2020-02-05 21:39   ` Pavel Begunkov [this message]
2020-02-05 21:43     ` Pavel Begunkov
2020-02-05 19:07 ` [PATCH 2/3] io_uring: deduce force_nonblock in io_issue_sqe() Pavel Begunkov
2020-02-05 19:07 ` [PATCH 3/3] io_uring: pass submission ref to async Pavel Begunkov
2020-02-05 22:29 ` [PATCH 0/3] io_uring: clean wq path Pavel Begunkov
2020-02-06  2:50   ` Jens Axboe
2020-02-06  9:51     ` Pavel Begunkov
2020-02-06 14:26       ` 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