]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
io_uring: fix memory ordering when SQPOLL thread goes to sleep
authorAlmog Khaikin <almogkh@gmail.com>
Mon, 21 Mar 2022 09:00:59 +0000 (11:00 +0200)
committerJens Axboe <axboe@kernel.dk>
Mon, 21 Mar 2022 12:33:29 +0000 (06:33 -0600)
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.

Signed-off-by: Almog Khaikin <almogkh@gmail.com>
Link: https://lore.kernel.org/r/20220321090059.46313-1-almogkh@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c

index 1a65d78804409d9290112c8acd8c400381dd1a3f..48f4540d7dd50a3161d7326358cbfbec7d2edb4b 100644 (file)
@@ -8042,6 +8042,13 @@ static int io_sq_thread(void *data)
                                        needs_sched = false;
                                        break;
                                }
+
+                               /*
+                                * Ensure the store of the wakeup flag is not
+                                * reordered with the load of the SQ tail
+                                */
+                               smp_mb();
+
                                if (io_sqring_entries(ctx)) {
                                        needs_sched = false;
                                        break;