libusb occasionally hangs after suspend/resume

Bug #1455924 reported by Alexander Ponyatykh
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
libusb (Debian)
New
Unknown
libusb (Ubuntu)
New
Medium
Unassigned

Bug Description

I'm trying to make g15daemon correctly recover after suspend/resume and found that it occasionally hangs after resume in libusb's usb_urb_transfer() (linux.c) on this line:
ioctl(dev->fd, IOCTL_USB_REAPURB, &context);

After some research I found that linux kernel internally has lists of pending and completed requests. All requests - successful or not - are moved from pending list to completed list, no requests should be lost. But it looks like after suspend/resume some request may be lost (may be a kernel bug). It that case IOCTL_USB_REAPURB would hang forever since request it's waiting for will never appear on completed list.

There is simple workaround. After preceding IOCTL_USB_DISCARDURB call our request is guaranteed to be completed, so there is no need to use blocking IOCTL_USB_DISCARDURB, we may use non-blocking IOCTL_USB_REAPURBNDELAY instead.

I've attached patch with this workaround. It also fixes race condition existed in original code, which may cause corruption of stack.

ProblemType: Bug
DistroRelease: Ubuntu 15.04
Package: libusb-0.1-4 2:0.1.12-25 [modified: lib/x86_64-linux-gnu/libusb-0.1.so.4.4.4]
ProcVersionSignature: Ubuntu 3.19.0-16.16-generic 3.19.3
Uname: Linux 3.19.0-16-generic x86_64
NonfreeKernelModules: fglrx
ApportVersion: 2.17.2-0ubuntu1
Architecture: amd64
CurrentDesktop: KDE
Date: Sun May 17 13:11:00 2015
Dependencies:
 gcc-5-base 5.1~rc1-0ubuntu1
 libc6 2.21-0ubuntu4
 libgcc1 1:5.1~rc1-0ubuntu1
 multiarch-support 2.21-0ubuntu4
SourcePackage: libusb
UpgradeStatus: Upgraded to vivid on 2015-04-26 (21 days ago)

Related branches

Revision history for this message
Alexander Ponyatykh (lazyranma) wrote :
Revision history for this message
Alexander Ponyatykh (lazyranma) wrote :

Please note that debug message about lost URB is not 100% accurate in multi-threaded code because of harmless race condition.

description: updated
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "12_hung_after_resume.diff" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
summary: - libusb occasionally hungs after suspend/resume
+ libusb occasionally hangs after suspend/resume
description: updated
Revision history for this message
Steve Langasek (vorlon) wrote :

I have rejected the referenced merge proposal because libusb is an obsolete library. The correct fix for this issue is to either migrate g15daemon to libusb-1.0, or replace libusb with libusb-compat-0.1 in the distribution.

Mathew Hodson (mhodson)
Changed in libusb (Ubuntu):
importance: Undecided → Medium
Changed in libusb (Debian):
status: Unknown → New
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.