linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hillf Danton <hdanton@sina.com>
To: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Petr Mladek <pmladek@suse.com>,
	Peter Zijlstra <peterz@infradead.org>
Subject: [RFC PATCH 2/8] workqueue: Make create_worker() safe against prematurely wakeups
Date: Thu,  4 Aug 2022 20:35:20 +0800	[thread overview]
Message-ID: <20220804123520.1660-1-hdanton@sina.com> (raw)
In-Reply-To: <20220804084135.92425-3-jiangshanlai@gmail.com>

On Thu,  4 Aug 2022 16:41:29 +0800 Lai Jiangshan wrote:
>  
> @@ -1942,6 +1943,7 @@ static struct worker *create_worker(struct worker_pool *pool)
>  		goto fail;
>  
>  	worker->id = id;
> +	worker->pool = pool;
>  
>  	if (pool->cpu >= 0)
>  		snprintf(id_buf, sizeof(id_buf), "%d:%d%s", pool->cpu, id,
> @@ -1949,6 +1951,7 @@ static struct worker *create_worker(struct worker_pool *pool)
>  	else
>  		snprintf(id_buf, sizeof(id_buf), "u%d:%d", pool->id, id);
>  
> +	reinit_completion(&pool->created);
>  	worker->task = kthread_create_on_node(worker_thread, worker, pool->node,
>  					      "kworker/%s", id_buf);
>  	if (IS_ERR(worker->task))
> @@ -1957,15 +1960,9 @@ static struct worker *create_worker(struct worker_pool *pool)
>  	set_user_nice(worker->task, pool->attrs->nice);
>  	kthread_bind_mask(worker->task, pool->attrs->cpumask);
>  
> -	/* successful, attach the worker to the pool */
> -	worker_attach_to_pool(worker, pool);
> -
>  	/* start the newly created worker */
> -	raw_spin_lock_irq(&pool->lock);
> -	worker->pool->nr_workers++;
> -	worker_enter_idle(worker);
>  	wake_up_process(worker->task);
> -	raw_spin_unlock_irq(&pool->lock);
> +	wait_for_completion(&pool->created);
>  
>  	return worker;

	cpu0	cpu1		cpu2
	===	===		===
		complete

	reinit_completion
				wait_for_completion

Any chance for race above?


       reply	other threads:[~2022-08-04 12:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220804084135.92425-1-jiangshanlai@gmail.com>
     [not found] ` <20220804084135.92425-3-jiangshanlai@gmail.com>
2022-08-04 12:35   ` Hillf Danton [this message]
2022-08-05  2:30     ` Lai Jiangshan
2022-08-06  8:02       ` Hillf Danton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220804123520.1660-1-hdanton@sina.com \
    --to=hdanton@sina.com \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox