Re: [PATCH] xhci: Do not create endpoint debugfs while holding the bandwidth mutex

From: Mathias Nyman
Date: Thu Jun 01 2023 - 10:13:55 EST


On 31.5.2023 15.40, Ricardo Ribalda Delgado wrote:
xhci_debugfs_create_endpoint needs to take the mm->mmap_sem, which is
not serialized with the hcd->bandwidth_mutex across the codebase.

Without this patch a deadlock has been observed with the uvc driver at
the functions v4l2_mmap() and usb_set_interface().

Cc: Stephen Boyd <swboyd@xxxxxxxxxxxx
Fixes: 167657a1bb5f ("xhci: don't create endpoint debugfs entry before ring buffer is set.")
Signed-off-by: Ricardo Ribalda Delgado <ribalda@xxxxxxxxxxxx>
---
I do not have a proper reproducer for this and I am not used to this
subsystem, so please take a careful look at this patch :).

Thanks!

Do you still have the lockdep output showing the deadlock?

I'm not sure how calling xhci_debugfs_create_endpoint() from
xhci_add_endpoint() instead of xhci_check_bandwidth() helps.

Both are called with hcd->bandwidth_mutex held:

usb_set_interface()
mutex_lock(hcd->bandwidth_mutex);
usb_hcd_alloc_bandwidth()
hcd->driver->add_endpoint() -> xhci_add_endpoint()
hcd->driver->check_bandwidth() -> xhci_check_bandwidth()
mutex_unlock(hcd->bandwidth_mutex);

Thanks
Mathias