Re: [PATCH] usb: core: Emit KOBJ_CHANGE on unbound interface

From: Fabien Sanglard

Date: Thu Oct 22 2026 - 14:29:45 EST


On Wed, Oct 14, 2026 at 07:01:31AM +0200, Greg Kroah-Hartman wrote:
> On Tue, Oct 13, 2026 at 09:48:21AM -0700, Fabien Sanglard wrote:
> > But it might be worth "trying". I am unsure what the kernel team
> > philosophy is in this regard. If you all agree, we could trigger the
> > KOBJ_CHANGE event unconditionally inside rebind_marked_interfaces()
> > instead of conditionally inside usb_rebind_intf().
>
> Please try and test to verify.

On Wed, Oct 21, 2026 at 10:01:24AM +0200, Oliver Neukum wrote:
> On a generic note, it seems to me that you are concerned about
> an unavoidable case. You can check whether an interface is
> unclaimed. Yet you have no way to ensure that the result of
> your check is still current and thus valid, at time you act
> upon it.
>
> In other words, you were about to design an interface that is
> inherently racy. That is not a good idea.

Emitting KOBJ_CHANGE unconditionally on the usb_device (&udev->dev.kobj)
in usb_reset_device() when ret == 0, right after
usb_unbind_and_rebind_marked_interfaces(udev), avoids the racy
unclaimed-interface check and is in line with the earlier feedback
("Why not always tell user space that a device has been reset?").
Instead of asserting that an interface is unclaimed, the event simply
tells userspace that the device has changed and, if tracked, should be
re-inspected.

I tested this across devices with snd-usb-audio (no pre/post_reset),
usbhid (with pre/post_reset), and usbfs (adb) using udevadm monitor:

Interface driver Uevent sequence on reset (ret == 0)
--------------------------------------------------------------------------
Kernel (no pre/post_reset) UNBIND(intf) -> BIND(intf) -> CHANGE(dev)
Kernel (with pre/post_reset) CHANGE(dev)
Userspace (usbfs, e.g. adb) UNBIND(intf) -> CHANGE(dev)

In all cases, CHANGE(dev) is emitted after in-kernel interface
rebinding has finished, notifying userspace that the reset is complete.
Because it is a usb_device uevent, it also includes DEVNAME (which
usb_interface uevents lack), making it trivial for usbfs clients to
re-inspect and re-claim the device without polling.

Thanks,
Fabien

-- >8 --
Subject: [PATCH v2] usb: core: Emit KOBJ_CHANGE when usb_reset_device() succeeds

When usb_reset_device() succeeds without re-enumerating the device,
userspace receives no device-level uevent indicating that the reset has
completed. For usbfs clients such as adb, usb_forced_unbind_intf()
unbinds the interface before the port reset, and device_attach() leaves
it unbound afterward because no kernel driver matches. Since usbfs
suppresses uevents on interface claim/release, userspace receives
UNBIND(intf) before the reset and no event when the device is ready to
be re-claimed, forcing it to fall back to polling /dev/bus/usb.

Emit KOBJ_CHANGE on &udev->dev.kobj in usb_reset_device() when the reset
succeeds, after usb_unbind_and_rebind_marked_interfaces(udev), so
userspace is notified (with DEVNAME) once the reset and all kernel
interface rebinding are complete.

Suggested-by: Oliver Neukum <oneukum@xxxxxxxx>
Signed-off-by: Fabien Sanglard <sanglardf@xxxxxxxxxx>
---
Changes in v2:
- Emit KOBJ_CHANGE on &udev->dev.kobj in usb_reset_device() after
usb_unbind_and_rebind_marked_interfaces() when ret == 0, instead of
on the interface in usb_rebind_intf().
- v1: https://lore.kernel.org/linux-usb/20261012171609.88273-1-sanglardf@xxxxxxxxxx/

drivers/usb/core/hub.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index b446905b4..4db428adf 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -6447,8 +6447,10 @@ int usb_reset_device(struct usb_device *udev)
}

/* If the reset failed, hub_wq will unbind drivers later */
- if (ret == 0)
+ if (ret == 0) {
usb_unbind_and_rebind_marked_interfaces(udev);
+ kobject_uevent(&udev->dev.kobj, KOBJ_CHANGE);
+ }
}

usb_autosuspend_device(udev);
--
2.55.0