Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1005EC6379F for ; Tue, 14 Feb 2023 02:03:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229558AbjBNCDX (ORCPT ); Mon, 13 Feb 2023 21:03:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjBNCDV (ORCPT ); Mon, 13 Feb 2023 21:03:21 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id A566410A98 for ; Mon, 13 Feb 2023 18:03:15 -0800 (PST) Received: (qmail 930176 invoked by uid 1000); 13 Feb 2023 21:03:14 -0500 Date: Mon, 13 Feb 2023 21:03:14 -0500 From: Alan Stern To: Boqun Feng Cc: Peter Zijlstra , Kent Overstreet , Kent Overstreet , Linus Torvalds , Coly Li , Tetsuo Handa , syzkaller , Dmitry Vyukov , Greg Kroah-Hartman , "Rafael J. Wysocki" , Ingo Molnar , LKML , USB list , Hillf Danton Subject: Re: [PATCH RFC] drivers/core: Replace lockdep_set_novalidate_class() with unique class keys Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 13, 2023 at 05:51:11PM -0800, Boqun Feng wrote: > Basically if you have two lock instances A and B with the same class, > and you know that locking ordering is always A -> B, then you can do > > mutex_lock(A); > mutex_lock_nest_lock(B, A); // lock B. > > to tell the lockdep this is not deadlock, plus lockdep will treat the > acquisition of A and the precondition of acquisition B, so the following > is not a deadlock as well: > > T1: > mutex_lock(A); > mutex_lock(C); > mutex_lock_nest_lock(B, A); > > T2: > mutex_lock(A); > mutex_lock_nest_lock(B, A); > mutex_lock(C); Why isn't this treated as a deadlock? It sure looks like a deadlock to me. Is this an example where lockdep just doesn't get the right answer? Alan Stern