From: Fabien Sanglard <sanglardf@google.com>
To: gregkh@linuxfoundation.org
Cc: oneukum@suse.com, stern@rowland.harvard.edu,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Fabien Sanglard <sanglardf@google.com>
Subject: Re: [PATCH] usb: core: Emit KOBJ_CHANGE on unbound interface
Date: Thu, 22 Oct 2026 18:29:32 +0000 [thread overview]
Message-ID: <20261022182932.3262876-1-sanglardf@google.com> (raw)
In-Reply-To: <f86ca4e0-b294-42cb-b51a-d9e9984544ef@suse.com>
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@suse.com>
Signed-off-by: Fabien Sanglard <sanglardf@google.com>
---
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@google.com/
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
prev parent reply other threads:[~2026-10-22 18:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <b7c2f7d1-40fd-4d83-8ced-5fc27e3be051@rowland.harvard.edu>
2026-10-12 17:16 ` Fabien Sanglard
2026-10-13 9:34 ` Oliver Neukum
2026-10-13 16:48 ` Fabien Sanglard
2026-10-14 5:01 ` Greg Kroah-Hartman
2026-10-21 8:01 ` Oliver Neukum
2026-10-22 18:29 ` Fabien Sanglard [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261022182932.3262876-1-sanglardf@google.com \
--to=sanglardf@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=oneukum@suse.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®