Linux USB
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Tasos Sahanidis <tasos@tasossah.com>
Cc: linux-usb@vger.kernel.org, gregkh@linuxfoundation.org
Subject: Re: [PATCH v3] usb: core: Don't hold the device lock while sleeping in do_proc_control()
Date: Thu, 31 Mar 2022 20:23:20 -0400	[thread overview]
Message-ID: <YkZF+Iepo7N1Xr0n@rowland.harvard.edu> (raw)
In-Reply-To: <3e299e2a-13b9-ddff-7fee-6845e868bc06@tasossah.com>

On Fri, Apr 01, 2022 at 12:47:00AM +0300, Tasos Sahanidis wrote:
> Since commit ae8709b296d8 ("USB: core: Make do_proc_control() and
> do_proc_bulk() killable") if a device has the USB_QUIRK_DELAY_CTRL_MSG
> quirk set, it will temporarily block all other URBs (e.g. interrupts)
> while sleeping due to a control.
> 
> This results in noticeable delays when, for example, a userspace usbfs
> application is sending URB interrupts at a high rate to a keyboard and
> simultaneously updates the lock indicators using controls. Interrupts
> with direction set to IN are also affected by this, meaning that
> delivery of HID reports (containing scancodes) to the usbfs application
> is delayed as well.
> 
> This patch fixes the regression by calling msleep() while the device
> mutex is unlocked, as was the case originally with usb_control_msg().
> 
> Fixes: ae8709b296d8 ("USB: core: Make do_proc_control() and do_proc_bulk() killable")
> Signed-off-by: Tasos Sahanidis <tasos@tasossah.com>
> ---

Acked-by: Alan Stern <stern@rowland.harvard.edu>

> v2: Resent as v1 got mangled
> v3: Renamed from: "usb: core: Don't block while sleeping in do_proc_control()"
> 
>  drivers/usb/core/devio.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index 6abb7294e919..b5b85bf80329 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -1209,12 +1209,16 @@ static int do_proc_control(struct usb_dev_state *ps,
>  
>  		usb_unlock_device(dev);
>  		i = usbfs_start_wait_urb(urb, tmo, &actlen);
> +
> +		/* Linger a bit, prior to the next control message. */
> +		if (dev->quirks & USB_QUIRK_DELAY_CTRL_MSG)
> +			msleep(200);
>  		usb_lock_device(dev);
>  		snoop_urb(dev, NULL, pipe, actlen, i, COMPLETE, tbuf, actlen);
>  		if (!i && actlen) {
>  			if (copy_to_user(ctrl->data, tbuf, actlen)) {
>  				ret = -EFAULT;
> -				goto recv_fault;
> +				goto done;
>  			}
>  		}
>  	} else {
> @@ -1231,6 +1235,10 @@ static int do_proc_control(struct usb_dev_state *ps,
>  
>  		usb_unlock_device(dev);
>  		i = usbfs_start_wait_urb(urb, tmo, &actlen);
> +
> +		/* Linger a bit, prior to the next control message. */
> +		if (dev->quirks & USB_QUIRK_DELAY_CTRL_MSG)
> +			msleep(200);
>  		usb_lock_device(dev);
>  		snoop_urb(dev, NULL, pipe, actlen, i, COMPLETE, NULL, 0);
>  	}
> @@ -1242,10 +1250,6 @@ static int do_proc_control(struct usb_dev_state *ps,
>  	}
>  	ret = (i < 0 ? i : actlen);
>  
> - recv_fault:
> -	/* Linger a bit, prior to the next control message. */
> -	if (dev->quirks & USB_QUIRK_DELAY_CTRL_MSG)
> -		msleep(200);
>   done:
>  	kfree(dr);
>  	usb_free_urb(urb);
> -- 
> 2.25.1
> 

      reply	other threads:[~2022-04-01  0:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31 21:47 [PATCH v3] usb: core: Don't hold the device lock while sleeping in do_proc_control() Tasos Sahanidis
2022-04-01  0:23 ` Alan Stern [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=YkZF+Iepo7N1Xr0n@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=tasos@tasossah.com \
    /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