Skip to contentSkip to conversation

io_uring: don't set IORING_SQ_NEED_WAKEUP when sqthread is dying

PATCH In review Hao Xu 2 participants 5 messages Apr 27, 2021 – Apr 28, 2021

Subsystems (2)
lore
Share & tools
lore

Hao Xu

author
#0 lore raw

PATCH 1/1 io_uring: don't set IORING_SQ_NEED_WAKEUP when sqthread is dying

we don't need to re-fork the sqthread over exec, so no need to set IORING_SQ_NEED_WAKEUP when sqthread is dying.

---
 fs/io_uring.c | 2 --
 1 file changed, 2 deletions(-)
fs/io_uring.c +0 -2
index 6b578c380e73..92dcd1c21516 100644
@@ -6897,8 +6897,6 @@ static int io_sq_thread(void *data)
 
 	io_uring_cancel_sqpoll(sqd);
 	sqd->thread = NULL;
-	list_for_each_entry(ctx, &sqd->ctx_list, sqd_list)
-		io_ring_set_wakeup_flag(ctx);
 	io_run_task_work();
 	io_run_task_work_head(&sqd->park_task_work);
 	mutex_unlock(&sqd->lock);
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 2 lines · Hao Xu

we don't need to re-fork the sqthread over exec, so no need to set IORING_SQ_NEED_WAKEUP when sqthread is dying.

It forces users to call io_uring_enter() for it to return -EOWNERDEAD. Consider that scenario with the ring given away to some other task not in current group, e.g. via socket.

if (ctx->flags & IORING_SETUP_SQPOLL) {
	io_cqring_overflow_flush(ctx, false);

	ret = -EOWNERDEAD;
	if (unlikely(ctx->sq_data->thread == NULL)) {
		goto out;
	}
	...
}

btw, can use a comment

Quoted 20 lines
---
 fs/io_uring.c | 2 --
 1 file changed, 2 deletions(-)
fs/io_uring.c +0 -2
index 6b578c380e73..92dcd1c21516 100644
@@ -6897,8 +6897,6 @@ static int io_sq_thread(void *data)
 
 	io_uring_cancel_sqpoll(sqd);
 	sqd->thread = NULL;
-	list_for_each_entry(ctx, &sqd->ctx_list, sqd_list)
-		io_ring_set_wakeup_flag(ctx);
 	io_run_task_work();
 	io_run_task_work_head(&sqd->park_task_work);
 	mutex_unlock(&sqd->lock);
Signature · 1 line
Pavel Begunkov
author
#2 lore raw
Quoted 8 lines · Pavel Begunkov
Quoted 2 lines · Hao Xu

we don't need to re-fork the sqthread over exec, so no need to set IORING_SQ_NEED_WAKEUP when sqthread is dying.

It forces users to call io_uring_enter() for it to return -EOWNERDEAD. Consider that scenario with the ring given away to some other task not in current group, e.g. via socket.

Ah, I see. Thank you Pavel.

Quoted 33 lines
if (ctx->flags & IORING_SETUP_SQPOLL) {
	io_cqring_overflow_flush(ctx, false);

	ret = -EOWNERDEAD;
	if (unlikely(ctx->sq_data->thread == NULL)) {
		goto out;
	}
	...
}

btw, can use a comment

Quoted 20 lines
---
  fs/io_uring.c | 2 --
  1 file changed, 2 deletions(-)
fs/io_uring.c +0 -2
index 6b578c380e73..92dcd1c21516 100644
@@ -6897,8 +6897,6 @@ static int io_sq_thread(void *data)
 
  	io_uring_cancel_sqpoll(sqd);
  	sqd->thread = NULL;
-	list_for_each_entry(ctx, &sqd->ctx_list, sqd_list)
-		io_ring_set_wakeup_flag(ctx);
  	io_run_task_work();
  	io_run_task_work_head(&sqd->park_task_work);
  	mutex_unlock(&sqd->lock);
author
#3 lore raw
Quoted 10 lines · Hao Xu
Quoted 8 lines · Pavel Begunkov
Quoted 2 lines · Hao Xu

we don't need to re-fork the sqthread over exec, so no need to set IORING_SQ_NEED_WAKEUP when sqthread is dying.

It forces users to call io_uring_enter() for it to return -EOWNERDEAD. Consider that scenario with the ring given away to some other task not in current group, e.g. via socket.

Ah, I see. Thank you Pavel.

Here I've a question: for processes that aren't in same group, io_uring is now designed that sqthread cannot be shared between these processes? But It seems if users do fork(), they can still call io_uring_enter() in the forked task?

Quoted 32 lines
Quoted 32 lines

if (ctx->flags & IORING_SETUP_SQPOLL) {
    io_cqring_overflow_flush(ctx, false);

    ret = -EOWNERDEAD;
    if (unlikely(ctx->sq_data->thread == NULL)) {
        goto out;
    }
    ...
}

btw, can use a comment

Quoted 19 lines

---
  fs/io_uring.c | 2 --

  1 file changed, 2 deletions(-)
fs/io_uring.c +0 -2
index 6b578c380e73..92dcd1c21516 100644
@@ -6897,8 +6897,6 @@ static int io_sq_thread(void *data)
       io_uring_cancel_sqpoll(sqd);
       sqd->thread = NULL;
-    list_for_each_entry(ctx, &sqd->ctx_list, sqd_list)
-        io_ring_set_wakeup_flag(ctx);
       io_run_task_work();
       io_run_task_work_head(&sqd->park_task_work);
       mutex_unlock(&sqd->lock);
 
#4 lore raw
Quoted 6 lines · Hao Xu
Quoted 5 lines · Hao Xu
Quoted 4 lines · Pavel Begunkov
Quoted 2 lines · Hao Xu

we don't need to re-fork the sqthread over exec, so no need to set IORING_SQ_NEED_WAKEUP when sqthread is dying.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

It forces users to call io_uring_enter() for it to return -EOWNERDEAD. Consider that scenario with the ring given away to some other task not in current group, e.g. via socket.

Ah, I see. Thank you Pavel.

Here I've a question: for processes that aren't in same group, io_uring is now designed that sqthread cannot be shared between these processes?

Right, sqthread can't be shared by rings created in different thread groups, but it doesn't mean the ring itself can't be shared.

Quoted 2 lines

But It seems if users do fork(), they can still call io_uring_enter() in the forked task?

IIRC, forking CLONE_THREAD task is discouraged but allowed, but in any case it's ok from the io_uring perspective. Requests will be fully executed in the context of the sqpoll task

Quoted 33 lines
Quoted 32 lines
Quoted 32 lines

if (ctx->flags & IORING_SETUP_SQPOLL) {
    io_cqring_overflow_flush(ctx, false);

    ret = -EOWNERDEAD;
    if (unlikely(ctx->sq_data->thread == NULL)) {
        goto out;
    }
    ...
}

btw, can use a comment

Quoted 19 lines

---
  fs/io_uring.c | 2 --

  1 file changed, 2 deletions(-)
fs/io_uring.c +0 -2
index 6b578c380e73..92dcd1c21516 100644
@@ -6897,8 +6897,6 @@ static int io_sq_thread(void *data)
       io_uring_cancel_sqpoll(sqd);
       sqd->thread = NULL;
-    list_for_each_entry(ctx, &sqd->ctx_list, sqd_list)
-        io_ring_set_wakeup_flag(ctx);
       io_run_task_work();
       io_run_task_work_head(&sqd->park_task_work);
       mutex_unlock(&sqd->lock);
 
Signature · 1 line
Pavel Begunkov