public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Tejun Heo <tj@kernel.org>, linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: single-threaded wq lockdep is broken
Date: Wed, 31 May 2017 10:36:36 +0200	[thread overview]
Message-ID: <1496219796.18378.1.camel@sipsolutions.net> (raw)
In-Reply-To: <CAJhGHyAREeJ9xkrwrNmVMkXndkmMtnRugWuYWB_x3BO1EywJ4A@mail.gmail.com> (sfid-20170531_103406_729347_2B44271A)

Hi,

> > #include <linux/kernel.h>
> > #include <linux/mutex.h>
> > #include <linux/workqueue.h>
> > #include <linux/module.h>
> > #include <linux/delay.h>
> > 
> > DEFINE_MUTEX(mtx);
> > static struct workqueue_struct *wq;
> > static struct work_struct w1, w2;
> > 
> > static void w1_wk(struct work_struct *w)
> > {
> >         mutex_lock(&mtx);
> >         msleep(100);
> >         mutex_unlock(&mtx);
> > }
> > 
> > static void w2_wk(struct work_struct *w)
> > {
> > }
> > 
> > /*
> >  * if not defined, then lockdep should warn only,
> 
> I guess when DEADLOCK not defined, there is no
> work is queued nor executed, therefore, no lock
> dependence is recorded, and there is no warn
> either.
> 
> >  * if defined, the system will really deadlock.
> >  */
> > 
> > //#define DEADLOCK
> > 
> > static int init(void)
> > {
> >         wq = create_singlethread_workqueue("test");
> >         if (!wq)
> >                 return -ENOMEM;
> >         INIT_WORK(&w1, w1_wk);
> >         INIT_WORK(&w2, w2_wk);
> > 
> 
>         /* add lock dependence, the lockdep should warn */
>         queue_work(wq, &w1);
>         queue_work(wq, &w2);
>         flush_work(&w1);
> 
> > #ifdef DEADLOCK
> >         queue_work(wq, &w1);
> >         queue_work(wq, &w2);
> > #endif
> >         mutex_lock(&mtx);
> >         flush_work(&w2);
> >         mutex_unlock(&mtx);
> > 
> > #ifndef DEADLOCK
> >         queue_work(wq, &w1);
> >         queue_work(wq, &w2);
> > #endif

This was "ifndef", so it does in fact run here, just like you
suggested. It doesn't warn though.

I don't think the order of queue/flush would matter, in fact, if you
insert it like you did, with the flush outside the mutex, no issue
exists (until the later flush)

johannes

  reply	other threads:[~2017-05-31  8:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-28 19:33 single-threaded wq lockdep is broken Johannes Berg
2017-05-31  8:34 ` Lai Jiangshan
2017-05-31  8:36   ` Johannes Berg [this message]
2017-05-31  8:47     ` Johannes Berg
2017-06-02  7:03     ` Lai Jiangshan
2017-06-02  8:51       ` Johannes Berg
2017-05-31 18:19 ` Tejun Heo
2017-05-31 19:15   ` Johannes Berg
2017-06-13 16:06 ` Tejun Heo

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=1496219796.18378.1.camel@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    /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