From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752079AbbHJLmh (ORCPT ); Mon, 10 Aug 2015 07:42:37 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:51113 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751625AbbHJLmc (ORCPT ); Mon, 10 Aug 2015 07:42:32 -0400 Date: Mon, 10 Aug 2015 13:42:28 +0200 From: Peter Zijlstra To: Boqun Feng Cc: Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [Question] lockdep: Is nested lock handled correctly? Message-ID: <20150810114228.GY16853@twins.programming.kicks-ass.net> References: <20150810095247.GA4606@fixme-laptop.cn.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150810095247.GA4606@fixme-laptop.cn.ibm.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 10, 2015 at 05:52:47PM +0800, Boqun Feng wrote: > Hi Peter and Ingo, > > I'm now learning the code of lockdep and find that nested lock may not > be handled correctly because we fail to take held_lock merging into > consideration. I come up with an example and hope that could explain my > concern. > > Please consider this lock/unlock sequence, I also put a patch ading this > sequence as a test into locking-selftest: > > (lock_X1 and lock_X2 belong to the same lock class X, lock_Y1 belongs to > another lock class Y) > > spin_lock(&lock_X1); > spin_lock(&lock_Y1); > spin_lock_nested_lock(&lock_X2, &lock_X1); > spin_unlock(&lock_Y1); > spin_unlock(&lock_X2); > spin_unlock(&lock_X1); > > > This is totally legal in current lockdep rules, right? Yuck, I'd say no. That's quite horrible. Why would you ever want to do that?