From: Tejun Heo <tj@kernel.org>
To: Li Bin <huawei.libin@huawei.com>
Cc: tanxiaofei <tanxiaofei@huawei.com>,
jiangshanlai@gmail.com, linux-kernel@vger.kernel.org,
John Garry <john.garry@huawei.com>
Subject: Re: [Question] null pointer risk of kernel workqueue
Date: Mon, 23 Oct 2017 07:03:21 -0700 [thread overview]
Message-ID: <20171023140321.GY1302522@devbig577.frc2.facebook.com> (raw)
In-Reply-To: <2f56ab49-4a65-8e35-07ba-6577af8843b6@huawei.com>
Hello,
On Mon, Oct 23, 2017 at 09:34:11AM +0800, Li Bin wrote:
>
>
> on 2017/10/21 23:35, Tejun Heo wrote:
> > On Fri, Oct 20, 2017 at 02:57:18PM +0800, tanxiaofei wrote:
> >> Hi Tejun,
> >>
> >> Any comments about this?
> >
> > I think you're confused, or at least can't understand what you're
> > trying to say. Can you create a rero?
> >
>
> Hi Tejun,
> The case is as following:
>
> worker_thread()
> |-spin_lock_irq()
> |-process_one_work()
> |-worker->current_pwq = pwq
> |-spin_unlock_irq()
> |-worker->current_func(work)
> |-spin_lock_irq()
> |-worker->current_pwq = NULL
> |-spin_unlock_irq()
> //interrupt here
> |-irq_handler
> |-__queue_work()
> //assuming that the wq is draining
> |-if (unlikely(wq->flags & __WQ_DRAINING) &&WARN_ON_ONCE(!is_chained_work(wq)))
> |-is_chained_work(wq)
> |-current_wq_worker() // Here, 'current' is the interrupted worker!
> |-current->current_pwq is NULL here!
> |-schedule()
>
> And I think the following patch can solve the bug, right?
>
> diff --git a/kernel/workqueue_internal.h b/kernel/workqueue_internal.h
> index 8635417..650680c 100644
> --- a/kernel/workqueue_internal.h
> +++ b/kernel/workqueue_internal.h
> @@ -59,7 +59,7 @@ struct worker {
> */
> static inline struct worker *current_wq_worker(void)
> {
> - if (current->flags & PF_WQ_WORKER)
> + if (!in_irq() && (current->flags & PF_WQ_WORKER))
> return kthread_data(current);
> return NULL;
> }
Yeah, that makes sense to me. Can you please resend the patch with
patch description and SOB?
Thanks.
--
tejun
next prev parent reply other threads:[~2017-10-23 14:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-23 9:04 [Question] null pointer risk of kernel workqueue tanxiaofei
2017-09-25 15:25 ` Tejun Heo
2017-09-27 9:17 ` tanxiaofei
2017-10-20 6:57 ` tanxiaofei
2017-10-21 15:35 ` Tejun Heo
2017-10-21 15:35 ` Tejun Heo
2017-10-23 1:34 ` Li Bin
2017-10-23 6:23 ` tanxiaofei
2017-10-23 14:03 ` Tejun Heo [this message]
2017-10-24 0:33 ` Li Bin
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=20171023140321.GY1302522@devbig577.frc2.facebook.com \
--to=tj@kernel.org \
--cc=huawei.libin@huawei.com \
--cc=jiangshanlai@gmail.com \
--cc=john.garry@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tanxiaofei@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.