Skip to contentSkip to conversation

io_uring: fix memory ordering when SQPOLL thread goes to sleep

PATCH Applied Almog Khaikin 2 participants 2 messages Mar 21, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 io_uring: fix memory ordering when SQPOLL thread goes to sleep

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.

---

v2: Fix trailing whitespace and rebase to latest tag

 fs/io_uring.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/io_uring.c +7 -0
index 5fa736344b67..695ee5fddc84 100644
@@ -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

Signature · 1 line
2.35.1
maintainer Applied
#1 lore raw
Quoted 8 lines · Almog Khaikin

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.

[...]

Applied, thanks!

[1/1] io_uring: fix memory ordering when SQPOLL thread goes to sleep

      commit: 649bb75d19c93f5459f450191953dff4825fda3e

Best regards,

Signature · 1 line
Jens Axboe