Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1671532pxb; Thu, 4 Nov 2021 06:35:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx30puQa5UDtZhR5v2b5PoLydTNwarE89eZNS3coED1z2GucBzodqVP3nR85TlJflnuIWhx X-Received: by 2002:adf:dd0a:: with SMTP id a10mr12027641wrm.60.1636032907897; Thu, 04 Nov 2021 06:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636032907; cv=none; d=google.com; s=arc-20160816; b=WokDJhj2zK/+ZrCL9xcQfcH4zXSCc2H3qYPv16DY+WBY77btxOGKePv0zj6o44BuC5 kxXoG2HAPPs3wWozixgXJOXUk81Ng92cjXsougHubpVQWMPZn3OIsCrZx7Rj68GQRobs PU+bCJ3+qdm9bW1UUTd9KFonytnpDUj6rtPebhaNwbNuZOahTZe97gDKFJ9ka93XD/6B 2AB18mW5p8TIq2EE8j3J3V5lkzqoHAL0B6ovL4ITp3sSIBREPcyV9AE680VXKVfY+t7w Ln43/3G7V7X37S3OAM6kHlWwzV4HO60fmz5W5xhywTnLmGtJvqhUwn3cAfU8vS7ARvCp Em9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=/2SMx7eja9dO7a3slyU46jQ4j1KyB3nMbK5dR/n9MIk=; b=Xulp7g99CEO0Ctut8zfecChoKzB1sl7dgTauf0lhOA6tGivLg6aQVz4sVQaI9kcZL1 BTGkVnU/fkqTMydpJ/yLmCug1h/qWhyC/iqdv9hdf3m9klkhkZ24wkGJlKp+5h1jnDNW nV+HHpziYvO4/A5/gcvwR2ToEaPyhWs3SN6Oe/+dKDFVo5w+zcyGQY5n2UW+9lPbEjUa TyyUJvOP6r4zmYR7N3SDcnUSFzdutoj4NCtOJtoIImcZJ6iWZMSKwJAr3tCIygqZpnS0 r37cb0Z+v5NA2fmu+ddGCHJmGIMN58L0BmmY49Zs24aiJFM64Id+5bZhi+sXUoxRhLdA e+dw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn4si8085855ejc.641.2021.11.04.06.34.23; Thu, 04 Nov 2021 06:35:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231152AbhKDNbH (ORCPT + 99 others); Thu, 4 Nov 2021 09:31:07 -0400 Received: from netrider.rowland.org ([192.131.102.5]:53759 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S231586AbhKDNbH (ORCPT ); Thu, 4 Nov 2021 09:31:07 -0400 Received: (qmail 1557484 invoked by uid 1000); 4 Nov 2021 09:28:28 -0400 Date: Thu, 4 Nov 2021 09:28:28 -0400 From: Alan Stern To: Benjamin Berg Cc: Marcel Holtmann , linux-usb@vger.kernel.org, linux-bluetooth@vger.kernel.org Subject: Re: Userspace enumeration hang while btusb tries to load firmware of removed device Message-ID: <20211104132828.GA1557201@rowland.harvard.edu> References: <20211103182303.GB1529362@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org On Thu, Nov 04, 2021 at 10:34:22AM +0100, Benjamin Berg wrote: > Hi Marcel and Alan, > > On Wed, 2021-11-03 at 20:31 +0100, Marcel Holtmann wrote: > > > I'm not familiar with the btusb driver, so someone on the > > > linux-bluetooth mailing list would have a better idea about this. > > > However, it does look as though btusb keeps the device locked during the > > > entire 10-second period while it tries to send over the firmware, and it > > > doesn't abort the procedure when it starts getting disconnection errors > > > but instead persists until a timeout expires. Keeping the device locked > > > would certainly block lsusb. > > > > > > In general, locking the device during a firmware upload seems like > > > the right thing to do -- you don't want extraneous transfers from > > > other processes messing up the firmware! So overall, it appears that > > > the whole problem would be solved if the firmware transfer were > > > aborted as soon as the -ENODEV errors start appearing. > > > > the problem seems to be that we hitting HCI command timeout. So the > > firmware download is done via HCI commands. These commands are send > > to the transport driver btusb.c via hdev->send (as btusb_send_frame). > > This triggers the usb_submit_urb or queues them via data->deferred > > anchor. All this reports back the error properly except that nobody > > does anything with it. > > > > See hci_send_frame() last portion: > > > > err = hdev->send(hdev, skb); > > if (err < 0) { > > bt_dev_err(hdev, "sending frame failed (%d)", err); > > kfree_skb(skb); > > } > > > > And that is it. We are not checking for ENODEV or any error here. > > That means the failure of the HCI command gets only caught via the > > HCI command timeout. I don’t know how to do this yet, but you would > > have to look there to fail HCI command right away instead of waiting > > for the timeout. > > Hmm, true, I don't see a "sending frame failed" error message during > the firmware download though. It is in the log you posted: [Mi Nov 3 11:55:23 2021] Bluetooth: hci0: Failed to send firmware data (-110) [Mi Nov 3 11:55:23 2021] Bluetooth: hci0: sending frame failed (-19) But this occurred after the timeout, so maybe you had in mind something occurring earlier. > You are right that this codepath is > loosing the error, but this does not seem to be the scenario we are > running into while loading the firmware. This error only happens later > on from the btintel_reset_to_bootloader function. > > What seems to happen in the posted log is that the URB is initially > submitted just fine and the transfer errors out afterwards. > Unfortunately, the btusb_tx_complete is only used for statistics > (stat.err_tx is increased) and has no further error handling that could > abort the firmware upload. While detecting the errors during URB completion would be nice, it isn't necessary. Things would work just as well if the disconnect error were detected during submission of the following URB. Alan Stern