io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>,
	io-uring@vger.kernel.org
Cc: asml.silence@gmail.com
Subject: Re: [RFC] io_uring: fix possible poll event lost in multi shot mode
Date: Thu, 2 Sep 2021 10:11:04 -0600	[thread overview]
Message-ID: <34f4e3a4-c10d-cdc2-4a30-807f620304ce@kernel.dk> (raw)
In-Reply-To: <20210902144843.2668-1-xiaoguang.wang@linux.alibaba.com>

On 9/2/21 8:48 AM, Xiaoguang Wang wrote:
> IIUC, IORING_POLL_ADD_MULTI is similar to epoll's edge-triggered mode,
> that means once one pure poll request returns one event(cqe), we'll
> need to read or write continually until EAGAIN is returned, then I think
> there is a possible poll event lost race in multi shot mode:
> 
> t1  poll request add |                         |
> t2                   |                         |
> t3  event happens    |                         |
> t4  task work add    |                         |
> t5                   | task work run           |
> t6                   |   commit one cqe        |
> t7                   |                         | user app handles cqe
> t8                   |   new event happen      |
> t9                   |   add back to waitqueue |
> t10                  |
> 
> After t6 but before t9, if new event happens, there'll be no wakeup
> operation, and if user app has picked up this cqe in t7, read or write
> until EAGAIN is returned. In t8, new event happens and will be lost,
> though this race window maybe small.
> 
> To fix this possible race, add poll request back to waitqueue before
> committing cqe.

This looks sane to me. Probably just needs a:

Fixes: 88e41cf928a6 ("io_uring: add multishot mode for IORING_OP_POLL_ADD")

tag.

-- 
Jens Axboe


      reply	other threads:[~2021-09-02 16:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-02 14:48 [RFC] io_uring: fix possible poll event lost in multi shot mode Xiaoguang Wang
2021-09-02 16:11 ` Jens Axboe [this message]

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=34f4e3a4-c10d-cdc2-4a30-807f620304ce@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=asml.silence@gmail.com \
    --cc=io-uring@vger.kernel.org \
    --cc=xiaoguang.wang@linux.alibaba.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).