Linux USB
 help / color / mirror / Atom feed
* [PATCH v2] usbip: Stop tracking work context in event_handler()
@ 2026-11-23 14:09 John Ernberg
  2026-11-23 14:17 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: John Ernberg @ 2026-11-23 14:09 UTC (permalink / raw)
  To: Valentina Manea, Shuah Khan, Greg Kroah-Hartman
  Cc: Hongren Zheng, Nobuo Iwata, linux-usb, linux-kernel,
	Wiliam Puranen, stable, John Ernberg, Michael Grzeschik

From: Wiliam Puranen <wiliam.puranen@actia.se>

The work queue used by usbip is not pinned to a specific context.

When usbip_in_eh() evaluates if the call comes from the event handler
it doesn't actually check if the call comes from the event handler but
if the call comes from the same context as the event handler was first
called from.

This can result in "sticky" devices on the client side, due to the
teardown path in stub_disconnect() being lied to, and thus skipping
the teardown when it shouldn't, or vice versa.

Fixes: bb7871ad99ea ("usbip: event handler as one thread")
Cc: stable@vger.kernel.org # v4.6+
Signed-off-by: Wiliam Puranen <wiliam.puranen@actia.se>
Signed-off-by: John Ernberg <john.ernberg@actia.se>
Reviewed-by: Michael Grzeschik <grzeschik@puzzle.ch>

---

Fixes an issue we've seen in our CI where USB devices remain in the client
after the server side has been suspended, even after the USB device having
been removed from the server.

AI was used to help us track down the issue and fix drafting. All testing,
verification, and final patch was done by humans.

v2:
 - Resent based on Shuah's request
 - Drop Assisted-by tag as those are not used anymore,
   shortly describe the parts AI was used for in the creation of the patch.
 - Pick up Michaels review tag
 - Rebased on latest usb-linus

v1: https://lore.kernel.org/linux-usb/20260803104342.2790105-1-john.ernberg@actia.se/
---
 drivers/usb/usbip/stub_dev.c     |  2 +-
 drivers/usb/usbip/usbip_common.h |  2 +-
 drivers/usb/usbip/usbip_event.c  | 10 ++--------
 3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
index abfa11d6bde7..407ac55d85c5 100644
--- a/drivers/usb/usbip/stub_dev.c
+++ b/drivers/usb/usbip/stub_dev.c
@@ -474,7 +474,7 @@ static void stub_disconnect(struct usb_device *udev)
 	}
 
 	/* If usb reset is called from event handler */
-	if (usbip_in_eh(current))
+	if (usbip_in_eh())
 		return;
 
 	/* we already have busid_priv, just lock busid_lock */
diff --git a/drivers/usb/usbip/usbip_common.h b/drivers/usb/usbip/usbip_common.h
index be4c5e65a7f8..2c91187e6469 100644
--- a/drivers/usb/usbip/usbip_common.h
+++ b/drivers/usb/usbip/usbip_common.h
@@ -321,7 +321,7 @@ int usbip_start_eh(struct usbip_device *ud);
 void usbip_stop_eh(struct usbip_device *ud);
 void usbip_event_add(struct usbip_device *ud, unsigned long event);
 int usbip_event_happened(struct usbip_device *ud);
-int usbip_in_eh(struct task_struct *task);
+int usbip_in_eh(void);
 
 static inline int interface_to_busnum(struct usb_interface *interface)
 {
diff --git a/drivers/usb/usbip/usbip_event.c b/drivers/usb/usbip/usbip_event.c
index 0e00c2d000f8..695af652c512 100644
--- a/drivers/usb/usbip/usbip_event.c
+++ b/drivers/usb/usbip/usbip_event.c
@@ -57,16 +57,10 @@ static struct usbip_device *get_event(void)
 	return ud;
 }
 
-static struct task_struct *worker_context;
-
 static void event_handler(struct work_struct *work)
 {
 	struct usbip_device *ud;
 
-	if (worker_context == NULL) {
-		worker_context = current;
-	}
-
 	while ((ud = get_event()) != NULL) {
 		usbip_dbg_eh("pending event %lx\n", ud->event);
 
@@ -186,9 +180,9 @@ int usbip_event_happened(struct usbip_device *ud)
 }
 EXPORT_SYMBOL_GPL(usbip_event_happened);
 
-int usbip_in_eh(struct task_struct *task)
+int usbip_in_eh(void)
 {
-	if (task == worker_context)
+	if (current_work() == &usbip_work)
 		return 1;
 
 	return 0;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] usbip: Stop tracking work context in event_handler()
  2026-11-23 14:09 [PATCH v2] usbip: Stop tracking work context in event_handler() John Ernberg
@ 2026-11-23 14:17 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-23 14:17 UTC (permalink / raw)
  To: John Ernberg; +Cc: linux-usb

> From: Wiliam Puranen <wiliam.puranen@actia.se>
> 
> The work queue used by usbip is not pinned to a specific context.
> 
> When usbip_in_eh() evaluates if the call comes from the event handler
> it doesn't actually check if the call comes from the event handler but
> if the call comes from the same context as the event handler was first
> called from.
> 
> This can result in "sticky" devices on the client side, due to the
> teardown path in stub_disconnect() being lied to, and thus skipping
> the teardown when it shouldn't, or vice versa.
> 
> Fixes: bb7871ad99ea ("usbip: event handler as one thread")
> Cc: stable@vger.kernel.org # v4.6+
> Signed-off-by: Wiliam Puranen <wiliam.puranen@actia.se>
> Signed-off-by: John Ernberg <john.ernberg@actia.se>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123140902.2177108-1-john.ernberg@actia.se?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-23 14:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 14:09 [PATCH v2] usbip: Stop tracking work context in event_handler() John Ernberg
2026-11-23 14:17 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox