From: Jens Axboe <axboe@kernel.dk>
To: yangerkun <yangerkun@huawei.com>, linux-block@vger.kernel.org
Cc: yi.zhang@huawei.com, houtao1@huawei.com
Subject: Re: [PATCH V2] io_uring: consider the overflow of sequence for timeout req
Date: Mon, 14 Oct 2019 14:10:45 -0600 [thread overview]
Message-ID: <b5143060-81b5-c6de-f5f9-f8d9a2186fdc@kernel.dk> (raw)
In-Reply-To: <20191014115156.43151-1-yangerkun@huawei.com>
On 10/14/19 5:51 AM, yangerkun wrote:
> The sequence for timeout req may overflow, and it will lead to wrong
> order of timeout req list. And we should consider two situation:
>
> 1. ctx->cached_sq_head + count - 1 may overflow;
> 2. cached_sq_head of now may overflow compare with before
> cached_sq_head.
>
> Fix the wrong logic by add record of count and use type long long to
> record the overflow.
>
> Signed-off-by: yangerkun <yangerkun@huawei.com>
> ---
> fs/io_uring.c | 31 +++++++++++++++++++++++++------
> 1 file changed, 25 insertions(+), 6 deletions(-)
>
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 76fdbe84aff5..c8dbf85c1c91 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -288,6 +288,7 @@ struct io_poll_iocb {
> struct io_timeout {
> struct file *file;
> struct hrtimer timer;
> + unsigned count;
> };
Can we reuse io_kiocb->submit->sequence for this? Unfortunately doing it
the way that you did, which does make the most logical sense, means that
struct io_kiocb will now spill into a 4th cacheline.
Or maybe fold ->sequence and ->submit.sequence to reclaim that space?
> @@ -1907,21 +1908,39 @@ static int io_timeout(struct io_kiocb *req, const struct io_uring_sqe *sqe)
> count = 1;
>
> req->sequence = ctx->cached_sq_head + count - 1;
> + req->timeout.count = count;
> req->flags |= REQ_F_TIMEOUT;
>
> /*
> * Insertion sort, ensuring the first entry in the list is always
> * the one we need first.
> */
> - tail_index = ctx->cached_cq_tail - ctx->rings->sq_dropped;
> - req_dist = req->sequence - tail_index;
> spin_lock_irq(&ctx->completion_lock);
> list_for_each_prev(entry, &ctx->timeout_list) {
> struct io_kiocb *nxt = list_entry(entry, struct io_kiocb, list);
> - unsigned dist;
> + unsigned nxt_sq_head;
> + long long tmp, tmp_nxt;
>
> - dist = nxt->sequence - tail_index;
> - if (req_dist >= dist)
> + /* count bigger than before should break directly. */
> + if (count >= nxt->timeout.count)
> + break;
Took me a bit, but I guess that's true. It's an optimization, maybe it'd be
cleaner if we just stuck to the sequence checking?
--
Jens Axboe
next prev parent reply other threads:[~2019-10-14 20:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-14 11:51 [PATCH V2] io_uring: consider the overflow of sequence for timeout req yangerkun
2019-10-14 20:10 ` Jens Axboe [this message]
2019-10-15 13:04 ` yangerkun
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 \
--in-reply-to=b5143060-81b5-c6de-f5f9-f8d9a2186fdc@kernel.dk \
--to=axboe@kernel.dk \
--cc=houtao1@huawei.com \
--cc=linux-block@vger.kernel.org \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
/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;
as well as URLs for NNTP newsgroup(s).