Re: [PATCH v2] usb: core: sysfs: show product, manufacturer and serial without the device lock
From: Joe Finzel
Date: Sat Dec 05 2026 - 06:34:19 EST
On Thu, Dec 03, 2026 at 07:06:11PM +0100, Greg Kroah-Hartman wrote:
> On Wed, Oct 14, 2026 at 11:01:51PM +0200, Joe Finzel via B4 Relay wrote:
> > is done -- seconds on a hub with several devices.
>
> "seconds"? USB isn't that slow.
Not per device, but it adds up because hub_event() keeps the hub locked
for the whole port loop. This is the root hub of the Z790 board from the
commit message, real hardware, 7.3.6:
[2.419] usb 1-2: new high-speed USB device number 2 using xhci_hcd
[4.295] hid-generic 0003:0B05:1A52.0001: ... [Generic USB Audio]
[4.408] usb 1-3: new full-speed USB device number 3 using xhci_hcd
[4.704] usb 1-4: new full-speed USB device number 4 using xhci_hcd
[4.950] usb 1-10: new high-speed USB device number 5 using xhci_hcd
[5.194] usb 1-11: new high-speed USB device number 6 using xhci_hcd
[5.600] usb 1-13: new high-speed USB device number 8 using xhci_hcd
[6.009] usb 1-14: new full-speed USB device number 10 using xhci_hcd
Most of it is the on-board audio device on port 2, which takes 1.9 s from
getting its address to its HID interface being bound (I haven't looked
into why yet); the other ports take 0.1-0.3 s each.
systemd stops udevd at 4.14 s and it exits at 6.15 s. In the last 40
boots of this machine the stop took 1.6-2.3 s, and every time it ended
141-152 ms after the "usb 1-14: new" line, so udevd waits for the root
hub's port loop to finish.
> qemu is "fake", so it can't provide real numbers, sorry. Use real
> hardware for testing this type of thing.
Fair enough. The numbers above are from the real machine; I only used
QEMU to show the effect of the patch reproducibly. I can run the same
board with the patch applied and send before/after numbers from it.
> They can still change.
The device can change them, but the kernel reads them only once:
usb_enumerate_device() sets udev->product, ->manufacturer and ->serial,
and nothing writes them again until usb_release_dev() frees them. If a
device comes back from a reset with different descriptors,
usb_reset_and_verify_device() re-enumerates it as a new device.
> What happens if the device goes away when this is called?
device_del() removes the attribute, and kernfs waits for any show() that
is already running (kernfs_drain()). The strings are only freed in
usb_release_dev(), after that.
> How is usb_lock_device() so slow? Is it because you are racing and
> trying to read the same device all at once and grabbing the lock and
> hitting the sleep in usb_lock_device() somehow? Why not turn that value
> down if that's the real issue?
There is no sleep in it, usb_lock_device() is device_lock(). It only
waits because hub_event() holds the same lock while it enumerates every
port, as above.
If you still prefer to keep the lock, I can drop the patch.
thanks,
Joe