[Xenial,1/1] USB: cdc-wdm: ignore -EPIPE from GetEncapsulatedResponse
diff mbox series

Message ID 20191105094109.25110-2-jesse.sung@canonical.com
State New
Headers show
Series
  • Fix for libmbim-proxy using 100% CPU
Related show

Commit Message

Wen-chien Jesse Sung Nov. 5, 2019, 9:41 a.m. UTC
From: Bjørn Mork <bjorn@mork.no>

BugLink: https://launchpad.net/bugs/1851347

The driver will forward errors to userspace after turning most of them
into -EIO. But all status codes are not equal. The -EPIPE (stall) in
particular can be seen more as a result of normal USB signaling than
an actual error. The state is automatically cleared by the USB core
without intervention from either driver or userspace.

And most devices and firmwares will never trigger a stall as a result
of GetEncapsulatedResponse. This is in fact a requirement for CDC WDM
devices. Quoting from section 7.1 of the CDC WMC spec revision 1.1:

  The function shall not return STALL in response to
  GetEncapsulatedResponse.

But this driver is also handling GetEncapsulatedResponse on behalf of
the qmi_wwan and cdc_mbim drivers. Unfortunately the relevant specs
are not as clear wrt stall. So some QMI and MBIM devices *will*
occasionally stall, causing the GetEncapsulatedResponse to return an
-EPIPE status. Translating this into -EIO for userspace has proven to
be harmful. Treating it as an empty read is safer, making the driver
behave as if the device was conforming to the CDC WDM spec.

There have been numerous reports of issues related to -EPIPE errors
from some newer CDC MBIM devices in particular, like for example the
Fibocom L831-EAU.  Testing on this device has shown that the issues
go away if we simply ignore the -EPIPE status.  Similar handling of
-EPIPE is already known from e.g. usb_get_string()

The -EPIPE log message is still kept to let us track devices with this
unexpected behaviour, hoping that it attracts attention from firmware
developers.

Cc: <stable@vger.kernel.org>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100938
Reported-and-tested-by: Christian Ehrig <christian.ehrig@mediamarktsaturn-bt.com>
Reported-and-tested-by: Patrick Chilton <chpatrick@gmail.com>
Reported-and-tested-by: Andreas Böhler <news@aboehler.at>
Signed-off-by: Bjørn Mork <bjorn@mork.no>
Acked-by: Oliver Neukum <oneukum@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(backported from commit 8fec9355a968ad240f3a2e9ad55b823cf1cc52ff)
Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>
---
 drivers/usb/class/cdc-wdm.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Connor Kuehl Nov. 6, 2019, 10:37 p.m. UTC | #1
On 11/5/19 1:41 AM, Wen-chien Jesse Sung wrote:
> (backported from commit 8fec9355a968ad240f3a2e9ad55b823cf1cc52ff)
> Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>

Acked-by: Connor Kuehl <connor.kuehl@canonical.com>

> ---
>   drivers/usb/class/cdc-wdm.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
> index 71ad04d54212..c2e3dcfa4ccd 100644
> --- a/drivers/usb/class/cdc-wdm.c
> +++ b/drivers/usb/class/cdc-wdm.c
> @@ -188,7 +188,12 @@ static void wdm_in_callback(struct urb *urb)
>   		}
>   	}
>   
> -	desc->rerr = status;
> +	/*
> +	 * Avoid propagating -EPIPE (stall) to userspace since it is
> +	 * better handled as an empty read
> +	 */
> +	desc->rerr = (status != -EPIPE) ? status : 0;
> +
>   	if (length + desc->length > desc->wMaxCommand) {
>   		/* The buffer would overflow */
>   		set_bit(WDM_OVERFLOW, &desc->flags);
>
AceLan Kao Nov. 7, 2019, 8:15 a.m. UTC | #2
Acked-By: AceLan Kao <acelan.kao@canonical.com>

Patch
diff mbox series

diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 71ad04d54212..c2e3dcfa4ccd 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -188,7 +188,12 @@  static void wdm_in_callback(struct urb *urb)
 		}
 	}
 
-	desc->rerr = status;
+	/*
+	 * Avoid propagating -EPIPE (stall) to userspace since it is
+	 * better handled as an empty read
+	 */
+	desc->rerr = (status != -EPIPE) ? status : 0;
+
 	if (length + desc->length > desc->wMaxCommand) {
 		/* The buffer would overflow */
 		set_bit(WDM_OVERFLOW, &desc->flags);