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 3DA0EC636D4 for ; Tue, 7 Feb 2023 17:46:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231491AbjBGRqg (ORCPT ); Tue, 7 Feb 2023 12:46:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231445AbjBGRqe (ORCPT ); Tue, 7 Feb 2023 12:46:34 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 4E90572B9 for ; Tue, 7 Feb 2023 09:46:33 -0800 (PST) Received: (qmail 703452 invoked by uid 1000); 7 Feb 2023 12:46:32 -0500 Date: Tue, 7 Feb 2023 12:46:32 -0500 From: Alan Stern To: Tetsuo Handa Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Peter Zijlstra , LKML , USB list , Hillf Danton , Linus Torvalds Subject: Re: Converting dev->mutex into dev->spinlock ? Message-ID: References: <917e1e3b-094f-e594-c1a2-8b97fb5195fd@I-love.SAKURA.ne.jp> <827177aa-bb64-87a9-e1af-dfe070744045@I-love.SAKURA.ne.jp> 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 Tue, Feb 07, 2023 at 10:07:18PM +0900, Tetsuo Handa wrote: > On 2023/02/07 0:45, Alan Stern wrote: > > On Mon, Feb 06, 2023 at 11:13:38PM +0900, Tetsuo Handa wrote: > >> On 2023/02/05 10:23, Alan Stern wrote: > >>> I suppose we could create separate lockdep classes for every bus_type > >>> and device_type combination, as well as for the different sorts of > >>> devices -- treat things like class devices separately from normal > >>> devices, and so on. But even then there would be trouble. > >> > >> Sorry, since I'm not familiar with devices, I can't interpret what you > >> are talking about in this response. But why don't you try test5() approach > >> in an example module shown below (i.e. treat all dev->mutex instances > >> independent to each other) ? > >> > >> Sharing mutex_init() (like test2() approach) causes false positives, > >> but allocating a key on each dev->mutex (like test5() approach) should > >> avoid false positives. > > > > Interesting idea. I'm doubtful that it will accomplish all that you > > want. After all, one of lockdep's biggest advantages is that it can > > detect the potential for deadlocks without a deadlock actually > > occurring. By putting each mutex into its own class, you lose much of > > this ability. > > > > But who knows? Maybe it will be a big help. > > > > Anyway, below is a patch you can try, based on the code for your test5. > > Let me know what happens. > > > > It boots, except lockdep_register_key() hit WARN_ON_ONCE() at > device_register(&platform_bus) from platform_bus_init(), for > platform_bus is a static object. > > struct device platform_bus = { > .init_name = "platform", > }; > > We need to skip lockdep_register_key()/lockdep_unregister_key() on > static "struct device" instances... Okay, no doubt you can modify the patch to handle that. The real question is what will happen in your syzbot test scenarios. Lockdep certainly ought to be able to detect a real deadlock when one occurs. It will be more interesting to find out if it can warn about potential deadlocks _without_ them occurring. Alan Stern