All of lore.kernel.org
 help / color / mirror / Atom feed
From: Almog Khaikin <almogkh@gmail.com>
To: Jens Axboe <axboe@kernel.dk>, io-uring@vger.kernel.org
Cc: asml.silence@gmail.com
Subject: Re: [PATCH] io_uring: fix memory ordering when SQPOLL thread goes to sleep
Date: Sun, 6 Mar 2022 23:35:30 +0200	[thread overview]
Message-ID: <b1699cff-b899-bc20-e7b8-14f7583a3193@gmail.com> (raw)
In-Reply-To: <33f74159-3dfa-f0ab-0b55-09916db837e8@kernel.dk>

On 3/6/22 23:00, Jens Axboe wrote:
> On 3/6/22 6:32 AM, Almog Khaikin wrote:
>> On 3/6/22 12:35, Almog Khaikin wrote:
>>> Without a full memory barrier between the store to the flags and the
>>> load of the SQ tail the two operations can be reordered and this can
>>> lead to a situation where the SQPOLL thread goes to sleep while the
>>> application writes to the SQ tail and doesn't see the wakeup flag.
>>> This memory barrier pairs with a full memory barrier in the application
>>> between its store to the SQ tail and its load of the flags.
>>
>> The IOPOLL list is internal to the kernel, userspace doesn't interact
>> with it. AFAICT it can't cause any races with userspace so the check if
>> the list is empty seems unnecessary. The flags and the SQ tail are the
>> only things that are shared that can cause any problems when the kernel
>> thread goes to sleep so I think it's safe to remove that check.
>>
>> The race here can result in a situation where the kernel thread goes to
>> sleep while the application updates the SQ tail and doesn't see the
>> NEED_WAKEUP flag. Checking the SQ tail after setting the wakeup flag
>> along with the full barrier would ensure that either we see the tail
>> update or the application sees the wakeup flag. The IOPOLL list doesn't
>> tie into any of this.
> 
> I think you're mixing up two different things, and even if not, the
> IOPOLL change should be a separate change.
> 
> The iopoll list check isn't about synchronizing with userspace, it's
> about not going to sleep if we have entries to reap. If we're running
> with IOPOLL|SQPOLL, then it's the sq poll thread that does the polling
> and reaping.

I understand that, but the iopoll list check is already done earlier in
the function and if the list isn't empty, the timer is reset. Checking
again just a little later in the function and after writing the
NEED_WAKEUP flag seems unnecessary but regardless, I guess it's not
really relevant to this patch as it's not a bug that the check is
there. The patch in the original message along with the liburing pull
request should fix the race.

      reply	other threads:[~2022-03-06 21:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-06 10:35 [PATCH] io_uring: fix memory ordering when SQPOLL thread goes to sleep Almog Khaikin
2022-03-06 13:32 ` Almog Khaikin
2022-03-06 21:00   ` Jens Axboe
2022-03-06 21:35     ` Almog Khaikin [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=b1699cff-b899-bc20-e7b8-14f7583a3193@gmail.com \
    --to=almogkh@gmail.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.