public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH v2] io_uring: fix memory ordering when SQPOLL thread goes to sleep
@ 2022-03-21  9:00 Almog Khaikin
  2022-03-21 12:33 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Almog Khaikin @ 2022-03-21  9:00 UTC (permalink / raw)
  To: io-uring; +Cc: axboe, asml.silence

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 <[email protected]>
---

v2: Fix trailing whitespace and rebase to latest tag

 fs/io_uring.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 5fa736344b67..695ee5fddc84 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8035,6 +8035,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;

base-commit: 5e929367468c8f97cd1ffb0417316cecfebef94b
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-21 12:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-21  9:00 [PATCH v2] io_uring: fix memory ordering when SQPOLL thread goes to sleep Almog Khaikin
2022-03-21 12:33 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox