* [PATCH 1/1] io_uring: don't touch sqd->thread off tw add
@ 2025-01-10 20:36 Pavel Begunkov
2025-01-10 20:40 ` Pavel Begunkov
2025-01-10 21:00 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Pavel Begunkov @ 2025-01-10 20:36 UTC (permalink / raw)
To: io-uring; +Cc: asml.silence, lizetao, Bui Quang Minh
With IORING_SETUP_SQPOLL all requests are created by the SQPOLL task,
which means that req->task should always match sqd->thread. Since
accesses to sqd->thread should be separately protected, use req->task
in io_req_normal_work_add() instead.
Note, in the eyes of io_req_normal_work_add(), the SQPOLL task struct
is always pinned and alive, and sqd->thread can either be the task or
NULL. It's only problematic if the compiler decides to reload the value
after the null check, which is not so likely.
Cc: [email protected]
Cc: Bui Quang Minh <[email protected]>
Reported-by: lizetao <[email protected]>
Fixes: 78f9b61bd8e54 ("io_uring: wake SQPOLL task when task_work is added to an empty queue")
Signed-off-by: Pavel Begunkov <[email protected]>
---
io_uring/io_uring.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index db198bd435b5..9b83b875d2e4 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1225,10 +1225,7 @@ static void io_req_normal_work_add(struct io_kiocb *req)
/* SQPOLL doesn't need the task_work added, it'll run it itself */
if (ctx->flags & IORING_SETUP_SQPOLL) {
- struct io_sq_data *sqd = ctx->sq_data;
-
- if (sqd->thread)
- __set_notify_signal(sqd->thread);
+ __set_notify_signal(tctx->task);
return;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] io_uring: don't touch sqd->thread off tw add
2025-01-10 20:36 [PATCH 1/1] io_uring: don't touch sqd->thread off tw add Pavel Begunkov
@ 2025-01-10 20:40 ` Pavel Begunkov
2025-01-10 21:00 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Pavel Begunkov @ 2025-01-10 20:40 UTC (permalink / raw)
To: io-uring; +Cc: lizetao, Bui Quang Minh
On 1/10/25 20:36, Pavel Begunkov wrote:
> With IORING_SETUP_SQPOLL all requests are created by the SQPOLL task,
> which means that req->task should always match sqd->thread. Since
> accesses to sqd->thread should be separately protected, use req->task
> in io_req_normal_work_add() instead.
>
> Note, in the eyes of io_req_normal_work_add(), the SQPOLL task struct
> is always pinned and alive, and sqd->thread can either be the task or
> NULL. It's only problematic if the compiler decides to reload the value
> after the null check, which is not so likely.
We don't have much time to drag it on, let's fix it up
so it hopefully gets into 6.13
> Cc: [email protected]
> Cc: Bui Quang Minh <[email protected]>
> Reported-by: lizetao <[email protected]>
> Fixes: 78f9b61bd8e54 ("io_uring: wake SQPOLL task when task_work is added to an empty queue")
> Signed-off-by: Pavel Begunkov <[email protected]>
> ---
> io_uring/io_uring.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
> index db198bd435b5..9b83b875d2e4 100644
> --- a/io_uring/io_uring.c
> +++ b/io_uring/io_uring.c
> @@ -1225,10 +1225,7 @@ static void io_req_normal_work_add(struct io_kiocb *req)
>
> /* SQPOLL doesn't need the task_work added, it'll run it itself */
> if (ctx->flags & IORING_SETUP_SQPOLL) {
> - struct io_sq_data *sqd = ctx->sq_data;
> -
> - if (sqd->thread)
> - __set_notify_signal(sqd->thread);
> + __set_notify_signal(tctx->task);
> return;
> }
>
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] io_uring: don't touch sqd->thread off tw add
2025-01-10 20:36 [PATCH 1/1] io_uring: don't touch sqd->thread off tw add Pavel Begunkov
2025-01-10 20:40 ` Pavel Begunkov
@ 2025-01-10 21:00 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-01-10 21:00 UTC (permalink / raw)
To: io-uring, Pavel Begunkov; +Cc: lizetao, Bui Quang Minh
On Fri, 10 Jan 2025 20:36:45 +0000, Pavel Begunkov wrote:
> With IORING_SETUP_SQPOLL all requests are created by the SQPOLL task,
> which means that req->task should always match sqd->thread. Since
> accesses to sqd->thread should be separately protected, use req->task
> in io_req_normal_work_add() instead.
>
> Note, in the eyes of io_req_normal_work_add(), the SQPOLL task struct
> is always pinned and alive, and sqd->thread can either be the task or
> NULL. It's only problematic if the compiler decides to reload the value
> after the null check, which is not so likely.
>
> [...]
Applied, thanks!
[1/1] io_uring: don't touch sqd->thread off tw add
commit: bd2703b42decebdcddf76e277ba76b4c4a142d73
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-10 21:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-10 20:36 [PATCH 1/1] io_uring: don't touch sqd->thread off tw add Pavel Begunkov
2025-01-10 20:40 ` Pavel Begunkov
2025-01-10 21:00 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox