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 093FDC05027 for ; Sun, 12 Feb 2023 15:23:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229657AbjBLPXs (ORCPT ); Sun, 12 Feb 2023 10:23:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbjBLPXq (ORCPT ); Sun, 12 Feb 2023 10:23:46 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id A979072A5 for ; Sun, 12 Feb 2023 07:23:45 -0800 (PST) Received: (qmail 880348 invoked by uid 1000); 12 Feb 2023 10:23:44 -0500 Date: Sun, 12 Feb 2023 10:23:44 -0500 From: Alan Stern To: Kent Overstreet Cc: Kent Overstreet , Linus Torvalds , Coly Li , Tetsuo Handa , syzkaller , Dmitry Vyukov , Greg Kroah-Hartman , "Rafael J. Wysocki" , Peter Zijlstra , Ingo Molnar , Boqun Feng , LKML , USB list , Hillf Danton Subject: Re: [PATCH RFC] drivers/core: Replace lockdep_set_novalidate_class() with unique class keys Message-ID: References: <52c7d509-ba9e-a121-60c9-138d7ff3f667@I-love.SAKURA.ne.jp> <109c3cc0-2c13-7452-4548-d0155c1aba10@gmail.com> 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 Sat, Feb 11, 2023 at 10:10:23PM -0500, Kent Overstreet wrote: > So IMO the more correct way to do this would be to change > device_initialize() to __device_initialize(), have it take a > lock_class_key as a parameter, and then use __mutex_init() instead of > mutex_init(). Yes, maybe. The increase in code size might outweigh the space saved. > But let's think about this more. Will there ever be situations where > lock ordering is dependent on what hardware is plugged into what, or > what hardware is plugged in first? Device lock ordering is always dependent on what hardware is plugged into what. However, I'm not aware of any situations where, given two different kinds of hardware, either one could be plugged into the other. Such things may exist but I can't think of any examples. On the other hand, there are obvious cases where two pieces of the _same_ kind of hardware can be plugged together in either order. USB hubs are a good example. Consider the possibility that a driver might want to lock all of a device's children at once. (I don't know if this ever happens, but it might.) Provided it acquires the parent device's lock first, this is utterly safe no matter what order the children are locked in. Try telling that to lockdep! In the end, we'd probably have to enforce a single fixed ordering. Alan Stern