Re: [PATCH v2] io_uring: simplify the SQPOLL thread check when cancelling requests

From: Pavel Begunkov
Date: Mon Jan 13 2025 - 16:34:15 EST


On 1/13/25 16:03, Bui Quang Minh wrote:
In io_uring_try_cancel_requests, we check whether sq_data->thread ==
current to determine if the function is called by the SQPOLL thread to do
iopoll when IORING_SETUP_SQPOLL is set. This check can race with the SQPOLL
thread termination.

io_uring_cancel_generic is used in 2 places: io_uring_cancel_generic and
io_ring_exit_work. In io_uring_cancel_generic, we have the information
whether the current is SQPOLL thread already. And the SQPOLL thread never
reaches io_ring_exit_work.

So to avoid the racy check, this commit adds a boolean flag to
io_uring_try_cancel_requests to determine if the caller is SQPOLL thread.

I think the comment is excessive, but let's leave it at that if
you don't want to respin it.

Reviewed-by: Pavel Begunkov <asml.silence@xxxxxxxxx>

--
Pavel Begunkov