lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Pine.LNX.4.44L0.0909021016550.2971-100000@iolanthe.rowland.org>
Date:	Wed, 2 Sep 2009 10:22:39 -0400 (EDT)
From:	Alan Stern <stern@...land.harvard.edu>
To:	Peter Zijlstra <peterz@...radead.org>
cc:	Jan Blunck <jblunck@...e.de>, Kay Sievers <kay.sievers@...e.de>,
	<gregkh@...e.de>, <kasievers@...e.de>,
	USB list <linux-usb@...r.kernel.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	linux-kernel <linux-kernel@...r.kernel.org>,
	Ingo Molnar <mingo@...e.hu>,
	Uwe Kleine-König 
	<u.kleine-koenig@...gutronix.de>
Subject: Re: driver/base/dd.c lockdep warning

On Wed, 2 Sep 2009, Peter Zijlstra wrote:

> There's a number of lockdep annotations to help out.
...

Thanks for the detailed explanation; I appreciate it.

> Now the particular issue at hand is that the device tree is a free form
> tree with (afaiu) unlimited lock nesting depth -- if you were to plug in
> an already daisy chained usb hub with actual devices on the 7th deep hub
> device discovery will hold the device locks for the root hub, all 7
> intermediate hubs and the child device, leading to a total of 9 locks.

That's true in principle but not in practice because of the way the USB 
hub driver is designed.  Children aren't discovered and registered when 
the parent is probed; they are handled later.

Of course, this kind of scenario absolutely could occur with other 
device types.

> And there is nothing fundamental -- other than the usb chain depth --
> that limits this scenario, imagine the device to be an i2c bus with yet
> more devices ;-)
> 
> [ There used to be the additional complexity that on suspend/resume
>   we would hold _ALL_ device locks, which would exceed the max we can
>   track for any one task, this however has long been fixed. ]
> 
> 
> So the proposal I currently have to solve this is to allocate 48 lock
> classes:
> 
> struct lock_class_key device_tree_depth[MAX_LOCK_DEPTH];
> 
> and when creating a new device node, set the lock class corresponding
> the depth in the tree:
> 
>   mutex_lock_init(&device->lock);
>   BUG_ON(device->depth >= MAX_LOCK_DEPTH); // surely we're not that deep
>   lockdep_set_class(&device->lock, device_tree_depth + device->depth);
>   ...
>   mutex_lock(&device->lock); /* already have parent locked */
>   device_attach(device, parent);
> 
> and take multiple child locks using:
> 
>   mutex_lock_nest_lock(&device->lock, &device->parent->lock);
> 
> Which, I think should work for most cases out there.

I agree.  It would be rather surprising to find a chain of devices 
nested more than 48 deep.

> Alan had some funny corner cases, but I think he wasn't sure whether
> those would indeed show up in reality.

Yes; there's no point worrying about them now.  This sounds like a good 
approach.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ