From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751182AbdEaIgl (ORCPT ); Wed, 31 May 2017 04:36:41 -0400 Received: from s3.sipsolutions.net ([5.9.151.49]:41734 "EHLO sipsolutions.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751019AbdEaIgj (ORCPT ); Wed, 31 May 2017 04:36:39 -0400 Message-ID: <1496219796.18378.1.camel@sipsolutions.net> Subject: Re: single-threaded wq lockdep is broken From: Johannes Berg To: Lai Jiangshan Cc: Tejun Heo , linux-kernel Date: Wed, 31 May 2017 10:36:36 +0200 In-Reply-To: (sfid-20170531_103406_729347_2B44271A) References: <1495999993.3578.1.camel@sipsolutions.net> (sfid-20170531_103406_729347_2B44271A) Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, > > #include > > #include > > #include > > #include > > #include > > > > 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