From patchwork Wed Aug 23 04:38:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boqun Feng X-Patchwork-Id: 9916539 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 79CCE603FF for ; Wed, 23 Aug 2017 04:38:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EFC0288B6 for ; Wed, 23 Aug 2017 04:38:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AD212895B; Wed, 23 Aug 2017 04:38:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7DD3288B6 for ; Wed, 23 Aug 2017 04:38:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753152AbdHWEhw (ORCPT ); Wed, 23 Aug 2017 00:37:52 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34773 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751477AbdHWEhu (ORCPT ); Wed, 23 Aug 2017 00:37:50 -0400 Received: by mail-pf0-f196.google.com with SMTP id m6so598733pfm.1; Tue, 22 Aug 2017 21:37:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+m+Qjoa384SvAm9irEsnrZKkY+U2Ymn7mbpArMtVG9w=; b=FIFUdvFcUxG0jMbQe9VHtHRTkfHQfAGwwnrZy/RXTjR782Unl7xQVvMiYRtUhRIFLk Ffm3MXosvuvu6tTgd66uhnzcOlJs2OrFvnsp8saMEaJbTqlU5Foz96krv0y6IOHIO4oy AzshTrqORnBSXgvXW7dEBm+6oUSZcjBNuc/kSqcs+FwsQSaOMgWVc4UhBMhtCvgg2Aha Zp7hK0V5COXugglsjG0gJRaw7lKfbPq9qflYLGGuBhSm0bv7FON/1lGtJifJ1VfePiBN prgt6y3XGz/McIERjc5V/SOjb/0C7xM4iAtKXOvdPmnr48qP2zNQJ1pMEmQr4qiHSwqn tXEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+m+Qjoa384SvAm9irEsnrZKkY+U2Ymn7mbpArMtVG9w=; b=okoER5n5fXBG3q5ZbfaNnDL6HtrzDwTRyHjNYE9/MLwmf6gtCpSKdNRAkOTIevBK/2 cXwrGF3cRQzCBQQWXggwTJ9Rhru70WevL3acldDCJcBofodTctvv6VPK7SWFcaBvpe6N IHFFaCwxXSHjc2HpNzvoAWeBNZuhWTVjrFF4mpahr17c/W6xYVjDCrR02L6GwhY6bP/g FSAr1keAEAmRJXeR0Q73Tz/shFrSIugWfDDl4wrFL71joddSzD7e5zvOuQI6SBFRz13k 8HjMeVgGu1oX8IwoSHDJq6S5cE4y9Kcqxn41iSK6tHU0Essw0kPV1prWcl8ssqBG6n8P M8bw== X-Gm-Message-State: AHYfb5gLHD3Mf9Z7Uv93S0kY40JnjkHdWVqAbWctO+n+Tlrvvemi/eki Q/A3W6oETftZjQ== X-Received: by 10.99.125.27 with SMTP id y27mr1398245pgc.249.1503463070202; Tue, 22 Aug 2017 21:37:50 -0700 (PDT) Received: from localhost ([45.32.52.191]) by smtp.gmail.com with ESMTPSA id z86sm771686pff.160.2017.08.22.21.37.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2017 21:37:48 -0700 (PDT) Date: Wed, 23 Aug 2017 12:38:13 +0800 From: Boqun Feng To: Byungchul Park Cc: Bart Van Assche , peterz@infradead.org, "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "sergey.senozhatsky.work@gmail.com" , "martin.petersen@oracle.com" , "axboe@kernel.dk" , "linux-scsi@vger.kernel.org" , "sfr@canb.auug.org.au" , "linux-next@vger.kernel.org" , kernel-team@lge.com Subject: Re: possible circular locking dependency detected [was: linux-next: Tree for Aug 22] Message-ID: <20170823043813.GH11771@tardis> References: <20170822183816.7925e0f8@canb.auug.org.au> <20170822104708.GA491@jagdpanzerIV.localdomain> <1503438234.2508.27.camel@wdc.com> <20170823000304.GK20323@X58A-UD3R> <20170823034951.GG11771@tardis> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170823034951.GG11771@tardis> User-Agent: Mutt/1.8.3 (2017-05-23) Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Aug 23, 2017 at 11:49:51AM +0800, Boqun Feng wrote: > Hi Byungchul, > > On Wed, Aug 23, 2017 at 09:03:04AM +0900, Byungchul Park wrote: > > On Tue, Aug 22, 2017 at 09:43:56PM +0000, Bart Van Assche wrote: > > > On Tue, 2017-08-22 at 19:47 +0900, Sergey Senozhatsky wrote: > > > > ====================================================== > > > > WARNING: possible circular locking dependency detected > > > > 4.13.0-rc6-next-20170822-dbg-00020-g39758ed8aae0-dirty #1746 Not tainted > > > > ------------------------------------------------------ > > > > fsck.ext4/148 is trying to acquire lock: > > > > (&bdev->bd_mutex){+.+.}, at: [] __blkdev_put+0x33/0x190 > > > > > > > > but now in release context of a crosslock acquired at the following: > > > > ((complete)&wait#2){+.+.}, at: [] blk_execute_rq+0xbb/0xda > > > > > > > > which lock already depends on the new lock. > > > > > > I felt this message really misleading, because the deadlock is detected > at the commit time of "((complete)&wait#2)" rather than the acquisition > time of "(&bdev->bd_mutex)", so I made the following improvement. > > Thoughts? > > Regards, > Boqun > While I'm on this one, I think we should also add a case in @check_src is a cross lock, i.e. we detect cross deadlock at the acquisition time of the cross lock. How about the following? Regards, Boqun --------------------------------------->8 From: Boqun Feng Date: Wed, 23 Aug 2017 12:12:16 +0800 Subject: [PATCH] lockdep: Print proper scenario if cross deadlock detected at acquisition time For a potential deadlock about CROSSRELEASE as follow: P1 P2 =========== ============= lock(A) lock(X) lock(A) commit(X) A: normal lock, X: cross lock , we could detect it at two places: 1. commit time: We have run P1 first, and have dependency A --> X in graph, and then we run P2, and find the deadlock. 2. acquisition time: We have run P2 first, and have dependency A --> X, in graph(because another P3 may run previously and is acquiring for lock X), and then we run P1 and find the deadlock. In current print_circular_lock_scenario(), for 1) we could print the right scenario and note that's a deadlock related to CROSSRELEASE, however for 2) we print the scenario as a normal lockdep deadlock. It's better to print a proper scenario related to CROSSRELEASE to help users find their bugs more easily, so improve this. Signed-off-by: Boqun Feng --- kernel/locking/lockdep.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 642fb5362507..a3709e15f609 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1156,6 +1156,23 @@ print_circular_lock_scenario(struct held_lock *src, __print_lock_name(target); printk(KERN_CONT ");\n"); printk("\n *** DEADLOCK ***\n\n"); + } else if (cross_lock(src->instance)) { + printk(" Possible unsafe locking scenario by crosslock:\n\n"); + printk(" CPU0 CPU1\n"); + printk(" ---- ----\n"); + printk(" lock("); + __print_lock_name(target); + printk(KERN_CONT ");\n"); + printk(" lock("); + __print_lock_name(source); + printk(KERN_CONT ");\n"); + printk(" lock("); + __print_lock_name(parent == source ? target : parent); + printk(KERN_CONT ");\n"); + printk(" unlock("); + __print_lock_name(source); + printk(KERN_CONT ");\n"); + printk("\n *** DEADLOCK ***\n\n"); } else { printk(" Possible unsafe locking scenario:\n\n"); printk(" CPU0 CPU1\n");