Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753050AbcD1MXO (ORCPT ); Thu, 28 Apr 2016 08:23:14 -0400 Received: from mga14.intel.com ([192.55.52.115]:3300 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752853AbcD1MXL (ORCPT ); Thu, 28 Apr 2016 08:23:11 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,546,1455004800"; d="asc'?scan'208";a="693704296" From: Felipe Balbi To: Jim Lin , Mathias Nyman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: gadget: f_fs: Fix kernel panic for SuperSpeed In-Reply-To: <571F2BA3.6040209@nvidia.com> References: <1461321780-3226-1-git-send-email-jilin@nvidia.com> <87bn51uagb.fsf@intel.com> <571E0058.6020007@nvidia.com> <87r3dtrj7b.fsf@intel.com> <571F2BA3.6040209@nvidia.com> User-Agent: Notmuch/0.21+96~g9bbc54b (http://notmuchmail.org) Emacs/25.0.90.3 (x86_64-pc-linux-gnu) Date: Thu, 28 Apr 2016 15:21:06 +0300 Message-ID: <871t5plya5.fsf@intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5999 Lines: 170 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, Jim Lin writes: > On 2016=E5=B9=B404=E6=9C=8825=E6=97=A5 20:01, Felipe Balbi wrote: >>>> Is this happening on set_config() ? If that's the case, why is >>>> gadget->speed set to USB_SPEED_SUPER to start with ? Your controller >>>> should already have negotiated highspeed which means >>>> function_descriptors() should have returned highspeed descriptors, not= a >>>> NULL superspeed. >>>> >>>> Care to explain why you haven't negotiated Highspeed ? The only thing I >>>> can think of is that you're using a Superspeed-capable peripheral >>>> controller (dwc3?) with maximum-speed set to Superspeed, with a >>>> Superspeed-capable cable connected to an XHCI PC, but loading a >>>> high-speed gadget driver (which you got from Android, written with f_f= s) >>>> and this gadget doesn't tell composite that its maximum speed is >>>> Highspeed, instead of super-speed. >>>> >>>> We can add a check, sure, to avoid a kernel oops; however, you should >>>> really fix up the gadget implementation and/or set dwc3's maximum-speed >>>> property accordingly. >>>> >>>> Can you check if this patch makes your scenario work while still being >>>> fully functional ? >>>> >>>> diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/compo= site.c >>>> index de9ffd60fcfa..3d3cdc5ed20d 100644 >>>> --- a/drivers/usb/gadget/composite.c >>>> +++ b/drivers/usb/gadget/composite.c >>>> @@ -66,20 +66,36 @@ function_descriptors(struct usb_function *f, >>>> { >>>> struct usb_descriptor_header **descriptors; >>>>=20=20=20=20 >>>> + /* >>>> + * NOTE: we try to help gadget drivers which might not be setting >>>> + * max_speed appropriately. >>>> + */ >>>> + >>>> switch (speed) { >>>> case USB_SPEED_SUPER_PLUS: >>>> descriptors =3D f->ssp_descriptors; >>>> - break; >>>> + if (descriptors) >>>> + break; >>>> + /* FALLTHROUGH */ >>>> case USB_SPEED_SUPER: >>>> descriptors =3D f->ss_descriptors; >>>> - break; >>>> + if (descriptors) >>>> + break; >>>> + /* FALLTHROUGH */ >>>> case USB_SPEED_HIGH: >>>> descriptors =3D f->hs_descriptors; >>>> - break; >>>> + if (descriptors) >>>> + break; >>>> + /* FALLTHROUGH */ >>>> default: >>>> descriptors =3D f->fs_descriptors; >>>> } >>>>=20=20=20=20 >>>> + /* >>>> + * if we can't find any descriptors at all, then this gadget deserve= s to >>>> + * Oops with a NULL pointer dereference >>>> + */ >>>> + >>>> return descriptors; >>>> } >>>>=20=20=20=20 >>> After trying your change, no kernel panic, but SuperSpeed device (device >>> mode) is not enumerated by ubuntu 14.04 USB 3.0 host controller as MTP >>> device with USB3.0 cable. >> what do you get on dmesg on host side ? Are you running dwc3 ? If you >> are, please capture trace logs of the failure: >> >> # mount -t debugfs none /sys/kernel/debug >> # cd /sys/kernel/debug/tracing >> # echo 2048 > buffer_size_kb >> # echo 1 > events/dwc3/enable >> >> (now connect your cable to host pc) >> >> # cp trace /path/to/non-volatile/storage/trace.txt >> >> Please reply with this trace.txt file and dmesg from host side. > This is not running with dwc3. okay > dmesg from PC host side (after adding your change without my patch): > > [17907.984647] usb 6-2: new SuperSpeed USB device number 54 using xhci_hcd > [17908.012036] usb 6-2: No SuperSpeed endpoint companion for config 1=20= =20 > interface 1 altsetting 0 ep 2: using minimum values > [17908.012040] usb 6-2: No SuperSpeed endpoint companion for config 1=20= =20 > interface 1 altsetting 0 ep 131: using minimum values > [17908.013652] usb 6-2: New USB device found, idVendor=3Dxxxx, idProduct= =3Dxxxx > [17908.013656] usb 6-2: New USB device strings: Mfr=3D1, Product=3D2,=20 > SerialNumber=3D3 > [17908.013658] usb 6-2: Product: xxxxxxx > [17908.013661] usb 6-2: Manufacturer: xxxxxx > [17908.013664] usb 6-2: SerialNumber: 1234567890 > [17908.014680] xhci_hcd 0000:05:00.0: ERROR: unexpected command=20 > completion code 0x11. hmmm... completed with unknown code ? Odd. Mathias, any idea what this is ? > [17908.014690] usb 6-2: can't set config #1, error -22 > > I also attach git log of system/core/adb/usb_linux_client.cpp of Android= =20 > N for your reference. > " > Author: Badhri Jagan Sridharan > Date: Mon Oct 5 13:04:03 2015 -0700 > > adbd: Add os descriptor support for adb. > > Eventhough windows does not rely on extended os > descriptor for adbd, when android usb device is > configures as a composite device such as mtp+adb, > windows discards the extended os descriptor even > if one of the USB function fails to send > the extended compat descriptor. This results in automatic > install of MTP driverto fail when Android device is in > "File Transfer" mode with adb enabled. > > https://msdn.microsoft.com/en-us/library/windows/hardware/gg463179.aspx > " Okay, cool. Can you check that you're limitting your controller's speed to high-speed ? =2D-=20 balbi --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXIgAzAAoJEIaOsuA1yqREZhEP/3OX1UpafZysOKLFtIsVAzu9 eu0GMUO2nfTibUvKLIiVecfe4HyOwYwP1s8Unx0dXtK/pxeXKrVD9+fabpBaa4U3 CXBaFvB0ezsi8YXjTFfcNmZ7XqZbLGS40JNeZFWSNqEWhuS6eWr6sPtDmm9caO2T VjVP5SrcBem2FtyfwCNSfcO5znanGEKVYahISzFQ97ypcMx3HVizgn3QzkphpXl6 gwfmkD5019P7DjvmSvMnTI6QT/ASsr6OuDBdUeyT8h8Q0UZ5En4DnEDTHnr6IBI/ 42HQVqb8rUJ3EzcGUPYanXvOGkUQIUkvTLVVSzCbWCZVxruAIP8Dr/4eJr8T7NO8 u27l88adhMKbJGOX2VHNXls+hd18TyAb9dNzshqKxq0vcf6lOqpekhTq0VQewj9m ozhL8GQAgimK1asP+Ndmx97r1+zb5PLWysrbz8lp2DVewzyQiVZpM41Hx1GjMGLR GMC4hpdQyvOFld+YgNg6Q9IS68GGHrkaQA6adZyR/KbyMoS8PEfu7w7TGTPX+B1/ 0mN6dg9Wu/nJcrt0AatcqUdUuq9SBhjN+/5wkunu7kGWHfuZcToG5S2YSXFUqta9 ToKyj1+YXe0RzPxj8ej21+CMVf5iC7dPq0FB766cNxkXiwFrVIWSRrwuSs95M7Uc JSSs5ZC0Xk/6FDMFU/Yv =1R7d -----END PGP SIGNATURE----- --=-=-=--