All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Libin <huawei.libin@huawei.com>
Cc: akpm@linux-foundation.org, tj@kernel.org,
	viro@zeniv.linux.org.uk, eparis@redhat.com, tglx@linutronix.de,
	rusty@rustcorp.com.au, ebiederm@xmission.com,
	john.stultz@linaro.org, mingo@redhat.com, peterz@infradead.org,
	gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	lizefan@huawei.com, jovi.zhangwei@huawei.com,
	guohanjun@huawei.com, zhangdianfang@huawei.com,
	wangyijing@huawei.com
Subject: Re: [PATCH 01/14] kthread: Fix invalid wakeup in kthreadd
Date: Thu, 29 Aug 2013 17:20:21 -0700	[thread overview]
Message-ID: <20130830002021.GZ3871@linux.vnet.ibm.com> (raw)
In-Reply-To: <1377784669-28140-2-git-send-email-huawei.libin@huawei.com>

On Thu, Aug 29, 2013 at 09:57:36PM +0800, Libin wrote:
> If kthreadd is preempted at(or before) location a, and the other thread,
> such as calling kthread_create_on_node(), adds a list item to
> the kthread_create_list followed with wake_up_process(kthread). After that
> when kthreadd is re-scheduled, calling set_current_state to set itself as
> state TASK_INTERRUPTIBLE, if it is preempted again after that and before
> __set_current_state(TASK_RUNNING), it triggers the invalid wakeup problem.
> ------------------------
> kthreadd()
> ------------------------
> ...
> for (;;) {
> 	//location a
> 	set_current_state(TASK_INTERRUPTIBLE);
> 	if (list_empty(&kthread_create_list)) {
> 		//location b
> 		schedule();
> 		//location c
> 	}
> 	__set_current_state(TASK_RUNNING);
> 	//location d
> ...
> ------------------------
> kthread_create_on_node()
> ------------------------
> ...
> spin_lock(&kthread_create_lock);
> list_add_tail(&create.list, &kthread_create_list);
> spin_unlock(&kthread_create_lock);
> ...
> wake_up_process(kthreadd_task);
> ...
> 
> To solve this problem, using preempt_disable() to bound the operaion that
> setting the task state and the conditions(set by the wake thread) validation.
> ------------------------
> kthreadd()
> ------------------------
> ...
> for (;;) {
> 	preempt_disable();
> 	set_current_state(TASK_INTERRUPTIBLE);
> 	if (list_empty(&kthread_create_list)) {
> 		preempt_enable();
> 		schedule();
> 		preempt_disable();
> 	}
> ...
> 
> Signed-off-by: Libin <huawei.libin@huawei.com>
> ---
>  kernel/kthread.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/kthread.c b/kernel/kthread.c
> index 760e86d..25c3fed 100644
> --- a/kernel/kthread.c
> +++ b/kernel/kthread.c
> @@ -456,10 +456,15 @@ int kthreadd(void *unused)
>  	current->flags |= PF_NOFREEZE;
> 
>  	for (;;) {
> +		preempt_disable();
>  		set_current_state(TASK_INTERRUPTIBLE);
> -		if (list_empty(&kthread_create_list))

And this one already has the list_empty() check after the call to
set_current_state(), so no change should be needed here.

On the other hand, if your testing shows that you are losing wakeups
with this exact code, please let us know!

							Thanx, Paul

> +		if (list_empty(&kthread_create_list)) {
> +			preempt_enable();
>  			schedule();
> +			preempt_disable();
> +		}
>  		__set_current_state(TASK_RUNNING);
> +		preempt_enable();
> 
>  		spin_lock(&kthread_create_lock);
>  		while (!list_empty(&kthread_create_list)) {
> -- 
> 1.8.2.1
> 
> 


  reply	other threads:[~2013-08-30  0:20 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-29 13:57 [PATCH 00/14] Fix bug about invalid wake up problem Libin
2013-08-29 13:57 ` [PATCH 01/14] kthread: Fix invalid wakeup in kthreadd Libin
2013-08-30  0:20   ` Paul E. McKenney [this message]
2013-08-29 13:57 ` [PATCH 02/14] audit: Fix invalid wakeup in kauditd_thread Libin
2013-08-29 13:57 ` [PATCH 03/14] audit: Fix invalid wakeup in wait_for_auditd Libin
2013-08-29 13:57 ` [PATCH 04/14] exit: Fix invalid wakeup in do_wait Libin
2013-08-29 13:57 ` [PATCH 05/14] hrtimer: Fix invalid wakeup in do_nanosleep Libin
2013-09-12 13:33   ` Thomas Gleixner
2013-08-29 13:57 ` [PATCH 06/14] irq: Fix invalid wakeup in irq_wait_for_interrupt Libin
2013-09-12 13:36   ` Thomas Gleixner
2013-08-29 13:57 ` [PATCH 07/14] module: Fix invalid wakeup in wait_for_zero_refcount Libin
2013-08-29 13:57 ` [PATCH 08/14] namespace: Fix invalid wakeup in zap_pid_ns_processes Libin
2013-08-29 13:57 ` [PATCH 09/14] rcutree: Fix invalid wakeup in rcu_wait Libin
2013-08-30  0:23   ` Paul E. McKenney
2013-08-29 13:57 ` [PATCH 10/14] time: Fix invalid wakeup in alarmtimer_do_nsleep Libin
2013-09-12 13:36   ` Thomas Gleixner
2013-08-29 13:57 ` [PATCH 11/14] trace: Fix invalid wakeup in wait_to_die Libin
2013-08-29 13:57 ` [PATCH 12/14] trace: Fix invalid wakeup in ring_buffer_consumer_thread Libin
2013-08-29 13:57 ` [PATCH 13/14] workqueue: Fix invalid wakeup in rescuer_thread Libin
2013-08-29 13:57 ` [PATCH 14/14] klist: Fix invalid wakeup in klist_remove Libin
2013-08-29 14:08 ` [PATCH 00/14] Fix bug about invalid wake up problem Libin
2013-08-29 14:12   ` Tejun Heo
2013-08-29 14:10 ` Tejun Heo
2013-08-29 23:39 ` Libin
2013-08-30  0:18 ` Paul E. McKenney

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=20130830002021.GZ3871@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=eparis@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=guohanjun@huawei.com \
    --cc=huawei.libin@huawei.com \
    --cc=john.stultz@linaro.org \
    --cc=jovi.zhangwei@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rusty@rustcorp.com.au \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wangyijing@huawei.com \
    --cc=zhangdianfang@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.