public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring: don't gate task_work run on TIF_NOTIFY_SIGNAL
@ 2022-09-29 21:33 Jens Axboe
  0 siblings, 0 replies; only message in thread
From: Jens Axboe @ 2022-09-29 21:33 UTC (permalink / raw)
  To: io-uring

This isn't a reliable mechanism to tell if we have task_work pending, we
really should be looking at whether we have any items queued. This is
problematic if forward progress is gated on running said task_work. One
such example is reading from a pipe, where the write side has been closed
right before the read is started. The fput() of the file queues TWA_RESUME
task_work, and we need that task_work to be run before ->release() is
called for the pipe. If ->release() isn't called, then the read will sit
forever waiting on data that will never arise.

Fix this by io_run_task_work() so it checks if we have task_work pending
rather than rely on TIF_NOTIFY_SIGNAL for that. The latter obviously
doesn't work for task_work that is queued without TWA_SIGNAL.

Cc: [email protected]
Link: https://github.com/axboe/liburing/issues/665
Signed-off-by: Jens Axboe <[email protected]>

---

diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 177bd55357d7..48ce2348c8c1 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -231,11 +231,11 @@ static inline unsigned int io_sqring_entries(struct io_ring_ctx *ctx)
 
 static inline int io_run_task_work(void)
 {
-	if (test_thread_flag(TIF_NOTIFY_SIGNAL)) {
+	if (task_work_pending(current)) {
+		if (test_thread_flag(TIF_NOTIFY_SIGNAL))
+			clear_notify_signal();
 		__set_current_state(TASK_RUNNING);
-		clear_notify_signal();
-		if (task_work_pending(current))
-			task_work_run();
+		task_work_run();
 		return 1;
 	}
 
-- 
Jens Axboe

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-29 21:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-29 21:33 [PATCH] io_uring: don't gate task_work run on TIF_NOTIFY_SIGNAL Jens Axboe

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