Skip to contentSkip to conversation

io_uring: don't submit sqes when ctx->refs is dying

PATCH In review Hao Xu 2 participants 2 messages Feb 19, 2021

Subsystems (2)
lore
Share & tools
lore

Hao Xu

author
#0 lore raw

PATCH 1/1 io_uring: don't submit sqes when ctx->refs is dying

When doing __io_uring_register() and waiting for references to exit, there could be other threads calling io_uring_enter() and submitting sqes which may cause the drain wait endless. So avoid this case by checking if ctx->refs is dying.

---
 fs/io_uring.c | 2 ++
 1 file changed, 2 insertions(+)
fs/io_uring.c +2 -0
index 931671082e61..9aab4d25c2df 100644
@@ -9356,6 +9356,8 @@ static int io_get_ext_arg(unsigned flags, const void __user *argp, size_t *argsz
 		}
 		submitted = to_submit;
 	} else if (to_submit) {
+		if (unlikely(percpu_ref_is_dying(&ctx->refs)))
+			goto out;
 		ret = io_uring_add_task_file(ctx, f.file);
 		if (unlikely(ret))
 			goto out;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 4 lines · Hao Xu

When doing __io_uring_register() and waiting for references to exit, there could be other threads calling io_uring_enter() and submitting sqes which may cause the drain wait endless. So avoid this case by checking if ctx->refs is dying.

IMHO, let's leave it as is because it noticeably changes behaviour. That's nothing that can't be solved in userspace if needed differently.

Quoted 20 lines
---
 fs/io_uring.c | 2 ++
 1 file changed, 2 insertions(+)
fs/io_uring.c +2 -0
index 931671082e61..9aab4d25c2df 100644
@@ -9356,6 +9356,8 @@ static int io_get_ext_arg(unsigned flags, const void __user *argp, size_t *argsz
 		}
 		submitted = to_submit;
 	} else if (to_submit) {
+		if (unlikely(percpu_ref_is_dying(&ctx->refs)))
+			goto out;
 		ret = io_uring_add_task_file(ctx, f.file);
 		if (unlikely(ret))
 			goto out;
Signature · 1 line
Pavel Begunkov