Re: [PATCH] kernel/kthread.c: need spin_lock_irq() for 'worker' beforemain looping, since it can "WARN_ON(worker->task)".

From: Chen Gang
Date: Wed Jun 19 2013 - 06:18:47 EST

On 06/19/2013 04:41 PM, Tejun Heo wrote:
> On Wed, Jun 19, 2013 at 12:03:38PM +0800, Chen Gang wrote:
>> >
>> > Since "WARN_ON(worker->task)", we can not assume that 'worker->task'
>> > will be NULL before set 'current' to it.
>> >
>> > So need let 'worker' lock protected too, just like it already lock
>> > protected all time in main looping.
> That synchronization is the kthread_worker user's responsibility. The
> locking around worker->task = NULL is to prevent the worker task being
> destroyed while insert_kthread_work() is trying to wake it up. It has
> nothing to do with the user trying to attach multiple tasks to the
> same kthread_worker. Plus, putting locking around WARN_ON() is
> pointless. It doesn't really fix anything. It just makes WARN_ON()
> trigger *slightly* more reliably.

Hmm... can 'worker->task' has chance to be not NULL before set 'current'
to it ?

why do we use WARN_ON(worker->task) ?

I guess it still has chance to let "worker->task != NULL", or it should
be BUG_ON(worker->task) instead of.

Chen Gang

Asianux Corporation
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at