Re: [PATCH] io_uring: fix io_sq_thread_stop running in front of io_sq_thread

Jens Axboe
2019-07-05T16:25:26Z

On 7/5/19 12:12 AM, Jackie Liu wrote:
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 4ef62a4..4bbecbb 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -231,6 +231,7 @@ struct io_ring_ctx {
> struct task_struct *sqo_thread; /* if using sq thread polling */
> struct mm_struct *sqo_mm;
> wait_queue_head_t sqo_wait;
> + bool sqo_thread_started;
>
> struct {
> /* CQ ring */
> @@ -2009,6 +2010,8 @@ static int io_sq_thread(void *data)
> unsigned inflight;
> unsigned long timeout;
>
> + ctx->sqo_thread_started = true;
> +
> old_fs = get_fs();
> set_fs(USER_DS);
>
> @@ -2243,6 +2246,8 @@ static int io_sqe_files_unregister(struct io_ring_ctx *ctx)
> static void io_sq_thread_stop(struct io_ring_ctx *ctx)
> {
> if (ctx->sqo_thread) {
> + while (!ctx->sqo_thread_started)
> + schedule();
> /*
> * The park is a bit of a work-around, without it we get
> * warning spews on shutdown with SQPOLL set and affinity
>

Probably want to make that an unsigned long, and then use
set_bit/test_bit for this to avoid funky memory ordering issues.

--
Jens Axboe