Skip to contentSkip to conversation

io_uring: remove req cancel in ->flush()

PATCH Applied Pavel Begunkov 3 participants 5 messages Oct 22, 2020

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

PATCH v2 1/1 io_uring: remove req cancel in ->flush()

Every close(io_uring) causes cancellation of all inflight requests carrying ->files. That's not nice but was neccessary up until recently. Now task->files removal is handled in the core code, so that part of flush can be removed.

---
v2: move exiting checks into io_uring_attempt_task_drop() (Jens)
remove not needed __io_uring_attempt_task_drop()

 fs/io_uring.c | 28 +++++-----------------------
 1 file changed, 5 insertions(+), 23 deletions(-)
fs/io_uring.c +5 -23
index 754363ff3ad6..29170bbdd708 100644
@@ -8668,19 +8668,11 @@ static void io_uring_del_task_file(struct file *file)
 		fput(file);
 }
 
-static void __io_uring_attempt_task_drop(struct file *file)
-{
-	struct file *old = xa_load(&current->io_uring->xa, (unsigned long)file);
-
-	if (old == file)
-		io_uring_del_task_file(file);
-}
-
 /*
  * Drop task note for this file if we're the only ones that hold it after
  * pending fput()
  */
-static void io_uring_attempt_task_drop(struct file *file, bool exiting)
+static void io_uring_attempt_task_drop(struct file *file)
 {
 	if (!current->io_uring)
 		return;
@@ -8688,10 +8680,9 @@ static void io_uring_attempt_task_drop(struct file *file, bool exiting)
 	 * fput() is pending, will be 2 if the only other ref is our potential
 	 * task file note. If the task is exiting, drop regardless of count.
 	 */
-	if (!exiting && atomic_long_read(&file->f_count) != 2)
-		return;
-
-	__io_uring_attempt_task_drop(file);
+	if (fatal_signal_pending(current) || (current->flags & PF_EXITING) ||
+	    atomic_long_read(&file->f_count) == 2)
+		io_uring_del_task_file(file);
 }
 
 void __io_uring_files_cancel(struct files_struct *files)
@@ -8749,16 +8740,7 @@ void __io_uring_task_cancel(void)
 
 static int io_uring_flush(struct file *file, void *data)
 {
-	struct io_ring_ctx *ctx = file->private_data;
-
-	/*
-	 * If the task is going away, cancel work it may have pending
-	 */
-	if (fatal_signal_pending(current) || (current->flags & PF_EXITING))
-		data = NULL;
-
-	io_uring_cancel_task_requests(ctx, data);
-	io_uring_attempt_task_drop(file, !data);
+	io_uring_attempt_task_drop(file);
 	return 0;
 }
 
Signature · 1 line
2.24.0
#1 lore raw
Quoted 4 lines · Pavel Begunkov

Every close(io_uring) causes cancellation of all inflight requests carrying ->files. That's not nice but was neccessary up until recently. Now task->files removal is handled in the core code, so that part of flush can be removed.

I don't understand the motivation for this patch. Why would an application close the io_uring fd with outstanding requests?

-Jeff

Quoted 65 lines

---
v2: move exiting checks into io_uring_attempt_task_drop() (Jens)
remove not needed __io_uring_attempt_task_drop()

 fs/io_uring.c | 28 +++++-----------------------
 1 file changed, 5 insertions(+), 23 deletions(-)
fs/io_uring.c +5 -23
index 754363ff3ad6..29170bbdd708 100644
@@ -8668,19 +8668,11 @@ static void io_uring_del_task_file(struct file *file)
 		fput(file);
 }
 
-static void __io_uring_attempt_task_drop(struct file *file)
-{
-	struct file *old = xa_load(&current->io_uring->xa, (unsigned long)file);
-
-	if (old == file)
-		io_uring_del_task_file(file);
-}
-
 /*
  * Drop task note for this file if we're the only ones that hold it after
  * pending fput()
  */
-static void io_uring_attempt_task_drop(struct file *file, bool exiting)
+static void io_uring_attempt_task_drop(struct file *file)
 {
 	if (!current->io_uring)
 		return;
@@ -8688,10 +8680,9 @@ static void io_uring_attempt_task_drop(struct file *file, bool exiting)
 	 * fput() is pending, will be 2 if the only other ref is our potential
 	 * task file note. If the task is exiting, drop regardless of count.
 	 */
-	if (!exiting && atomic_long_read(&file->f_count) != 2)
-		return;
-
-	__io_uring_attempt_task_drop(file);
+	if (fatal_signal_pending(current) || (current->flags & PF_EXITING) ||
+	    atomic_long_read(&file->f_count) == 2)
+		io_uring_del_task_file(file);
 }
 
 void __io_uring_files_cancel(struct files_struct *files)
@@ -8749,16 +8740,7 @@ void __io_uring_task_cancel(void)
 
 static int io_uring_flush(struct file *file, void *data)
 {
-	struct io_ring_ctx *ctx = file->private_data;
-
-	/*
-	 * If the task is going away, cancel work it may have pending
-	 */
-	if (fatal_signal_pending(current) || (current->flags & PF_EXITING))
-		data = NULL;
-
-	io_uring_cancel_task_requests(ctx, data);
-	io_uring_attempt_task_drop(file, !data);
+	io_uring_attempt_task_drop(file);
 	return 0;
 }
maintainer
#2 lore raw
Quoted 9 lines · Jeff Moyer
Quoted 4 lines · Pavel Begunkov

Every close(io_uring) causes cancellation of all inflight requests carrying ->files. That's not nice but was neccessary up until recently. Now task->files removal is handled in the core code, so that part of flush can be removed.

I don't understand the motivation for this patch. Why would an application close the io_uring fd with outstanding requests?

It normally wouldn't, of course. It's important to understand that this triggers for _any_ close. So if the app did a dup+close, then it'd still trigger.

The point is that previously we _had_ to cancel requests that had ->files assigned, due to using a weak reference. Now we no longer have to, so the point is to just get rid of that previous oddity.

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 8 lines · Jens Axboe
Quoted 7 lines · Jeff Moyer
Quoted 4 lines · Pavel Begunkov

Every close(io_uring) causes cancellation of all inflight requests carrying ->files. That's not nice but was neccessary up until recently. Now task->files removal is handled in the core code, so that part of flush can be removed.

Quoted 6 lines
Quoted 2 lines

I don't understand the motivation for this patch. Why would an application close the io_uring fd with outstanding requests?

It normally wouldn't, of course. It's important to understand that this triggers for _any_ close. So if the app did a dup+close, then it'd still trigger.

Ah, I see. That makes more sense, thanks.

-Jeff

maintainer Applied
#4 lore raw
In reply to Pavel Begunkov
Quoted 4 lines · Pavel Begunkov

Every close(io_uring) causes cancellation of all inflight requests carrying ->files. That's not nice but was neccessary up until recently. Now task->files removal is handled in the core code, so that part of flush can be removed.

Applied, thanks.

Signature · 1 line
Jens Axboe