* [PATCH] workqueue: Fix possible unexpectedly worker wakeup before started
@ 2014-02-19 3:47 Lai Jiangshan
2014-02-20 0:11 ` Tejun Heo
0 siblings, 1 reply; 4+ messages in thread
From: Lai Jiangshan @ 2014-02-19 3:47 UTC (permalink / raw)
To: Tejun Heo; +Cc: Lai Jiangshan, linux-kernel
If a worker is wokenup unexpectedly, it will start to work incorretly.
Although it hardly happen, we should catch it and wait for being started
if it does happen.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
kernel/workqueue.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 82ef9f3..bee5fe1 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2284,6 +2284,12 @@ static int worker_thread(void *__worker)
struct worker *worker = __worker;
struct worker_pool *pool = worker->pool;
+ if (WARN_ON_ONCE(!(worker->flags & WORKER_STARTED))) {
+ /* The worker is wokenup unexpectedly before started */
+ mutex_lock(&pool->manager_mutex);
+ mutex_unlock(&pool->manager_mutex);
+ }
+
/* tell the scheduler that this is a workqueue worker */
worker->task->flags |= PF_WQ_WORKER;
woke_up:
--
1.7.4.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] workqueue: Fix possible unexpectedly worker wakeup before started
2014-02-19 3:47 [PATCH] workqueue: Fix possible unexpectedly worker wakeup before started Lai Jiangshan
@ 2014-02-20 0:11 ` Tejun Heo
2014-02-20 1:50 ` Lai Jiangshan
0 siblings, 1 reply; 4+ messages in thread
From: Tejun Heo @ 2014-02-20 0:11 UTC (permalink / raw)
To: Lai Jiangshan; +Cc: linux-kernel
Hello, Lai.
On Wed, Feb 19, 2014 at 11:47:58AM +0800, Lai Jiangshan wrote:
> If a worker is wokenup unexpectedly, it will start to work incorretly.
> Although it hardly happen, we should catch it and wait for being started
> if it does happen.
Can this actually happen? If so, how?
> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
> ---
> kernel/workqueue.c | 6 ++++++
> 1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index 82ef9f3..bee5fe1 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -2284,6 +2284,12 @@ static int worker_thread(void *__worker)
> struct worker *worker = __worker;
> struct worker_pool *pool = worker->pool;
>
> + if (WARN_ON_ONCE(!(worker->flags & WORKER_STARTED))) {
And if this is something which can legitimately happen, why are we
triggering WARN on it?
> + /* The worker is wokenup unexpectedly before started */
> + mutex_lock(&pool->manager_mutex);
> + mutex_unlock(&pool->manager_mutex);
And what does these mutex cycling achieve (they need comment)?
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] workqueue: Fix possible unexpectedly worker wakeup before started
2014-02-20 0:11 ` Tejun Heo
@ 2014-02-20 1:50 ` Lai Jiangshan
2014-02-20 2:01 ` Lai Jiangshan
0 siblings, 1 reply; 4+ messages in thread
From: Lai Jiangshan @ 2014-02-20 1:50 UTC (permalink / raw)
To: Tejun Heo; +Cc: linux-kernel
On 02/20/2014 08:11 AM, Tejun Heo wrote:
> Hello, Lai.
>
> On Wed, Feb 19, 2014 at 11:47:58AM +0800, Lai Jiangshan wrote:
>> If a worker is wokenup unexpectedly, it will start to work incorretly.
>> Although it hardly happen, we should catch it and wait for being started
>> if it does happen.
>
> Can this actually happen? If so, how?
I don't think it can happen.
It depends on the system outside of workqueue.
I'm afraid someone see the task and wake up it.
workqueue protect itself.
>
>> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
>> ---
>> kernel/workqueue.c | 6 ++++++
>> 1 files changed, 6 insertions(+), 0 deletions(-)
>>
>> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
>> index 82ef9f3..bee5fe1 100644
>> --- a/kernel/workqueue.c
>> +++ b/kernel/workqueue.c
>> @@ -2284,6 +2284,12 @@ static int worker_thread(void *__worker)
>> struct worker *worker = __worker;
>> struct worker_pool *pool = worker->pool;
>>
>> + if (WARN_ON_ONCE(!(worker->flags & WORKER_STARTED))) {
>
> And if this is something which can legitimately happen, why are we
> triggering WARN on it?
If it happens, it means there is something wrong in the system.
>
>> + /* The worker is wokenup unexpectedly before started */
>> + mutex_lock(&pool->manager_mutex);
>> + mutex_unlock(&pool->manager_mutex);
>
> And what does these mutex cycling achieve (they need comment)?
Synchronize the manager to finish.
>
> Thanks.
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] workqueue: Fix possible unexpectedly worker wakeup before started
2014-02-20 1:50 ` Lai Jiangshan
@ 2014-02-20 2:01 ` Lai Jiangshan
0 siblings, 0 replies; 4+ messages in thread
From: Lai Jiangshan @ 2014-02-20 2:01 UTC (permalink / raw)
To: Tejun Heo; +Cc: linux-kernel
On 02/20/2014 09:50 AM, Lai Jiangshan wrote:
> On 02/20/2014 08:11 AM, Tejun Heo wrote:
>> Hello, Lai.
>>
>> On Wed, Feb 19, 2014 at 11:47:58AM +0800, Lai Jiangshan wrote:
>>> If a worker is wokenup unexpectedly, it will start to work incorretly.
>>> Although it hardly happen, we should catch it and wait for being started
>>> if it does happen.
>>
>> Can this actually happen? If so, how?
>
> I don't think it can happen.
> It depends on the system outside of workqueue.
>
> I'm afraid someone see the task and wake up it.
> workqueue protect itself.
I was extremely nervously, please drop the patch.
I also don't like too much protective code in workqueue.
>
>>
>>> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
>>> ---
>>> kernel/workqueue.c | 6 ++++++
>>> 1 files changed, 6 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
>>> index 82ef9f3..bee5fe1 100644
>>> --- a/kernel/workqueue.c
>>> +++ b/kernel/workqueue.c
>>> @@ -2284,6 +2284,12 @@ static int worker_thread(void *__worker)
>>> struct worker *worker = __worker;
>>> struct worker_pool *pool = worker->pool;
>>>
>>> + if (WARN_ON_ONCE(!(worker->flags & WORKER_STARTED))) {
>>
>> And if this is something which can legitimately happen, why are we
>> triggering WARN on it?
>
> If it happens, it means there is something wrong in the system.
>
>>
>>> + /* The worker is wokenup unexpectedly before started */
>>> + mutex_lock(&pool->manager_mutex);
>>> + mutex_unlock(&pool->manager_mutex);
>>
>> And what does these mutex cycling achieve (they need comment)?
>
> Synchronize the manager to finish.
>
>>
>> Thanks.
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-02-20 1:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-19 3:47 [PATCH] workqueue: Fix possible unexpectedly worker wakeup before started Lai Jiangshan
2014-02-20 0:11 ` Tejun Heo
2014-02-20 1:50 ` Lai Jiangshan
2014-02-20 2:01 ` Lai Jiangshan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox