Re: driver/base/dd.c lockdep warning

From: Alan Stern
Date: Wed Sep 02 2009 - 10:22:45 EST

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

Alan Stern

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at