Le 19/04/2016 11:52, Stefan Bühler a écrit :
Package: libccid Version: 1.4.22-1 Tags: patch Severity: importantHi, after suspend/resume pcscd burns a core: --- [pid 23458] poll([{fd=6, events=POLLIN}, {fd=5, events=POLLIN}], 2, 4294967295) = 1 ([{fd=5, revents=POLLIN}]) [pid 23458] recvmsg(11, 0x7f0332553d80, 0) = -1 EAGAIN (Resource temporarily unavailable) [pid 23458] poll([{fd=6, events=POLLIN}, {fd=5, events=POLLIN}], 2, 4294967295) = 1 ([{fd=5, revents=POLLIN}]) [pid 23458] recvmsg(11, 0x7f0332553d80, 0) = -1 EAGAIN (Resource temporarily unavailable) --- Some rounds of debugging and reading source lead me to a bug in ccid: after initializing a certain reader failed pcscd unloads ccid, which unloads libusb without proper cleanup. This leads to various race conditions if libusb gets loaded again later, and might crash pcscd in other cases. --- Apr 19 10:08:13 $hostname systemd[1]: Started PC/SC Smart Card Daemon. Apr 19 10:08:13 $hostname pcscd[10047]: 00000000 ifdhandler.c:144:CreateChannelByNameOrChannel() failed Apr 19 10:08:13 $hostname pcscd[10047]: 00000036 readerfactory.c:1097:RFInitializeReader() Open Port 0x200000 Failed (usb:0a5c/5800:libudev:0:/dev/bus/usb/004/003) Apr 19 10:08:13 $hostname pcscd[10047]: 00000004 readerfactory.c:372:RFAddReader() Broadcom Corp 5880 [Broadcom USH] (0123456789ABCD) init failed. --- See attached patch for a fix.
Wonderful. You patch fixes a problem I (wrongly) thought was in libudev. I committed your patch upstream in https://alioth.debian.org/plugins/scmgit/cgi-bin/gitweb.cgi?p=pcsclite/CCID.git;a=commit;h=3c21f452543983f3625a1965ce234074cbda6865 "Fix a busy loop consuming 100% of CPU If opening a reader fails then we must call close_libusb_if_needed() to free any libusb resources and stop the libusb hotplug thread. The problem as been detected with the Yubico Yubikey NEO U2F+CCID and the 2 Boardcom devices. These devices are composite USB devices so loading the CCID driver for a non-CCID interface was calling libusb_init() but not libusb_exit(). The libusb hotplug thread and other libusb allocated resources were not stopped and unallocated. On the next USB plug (even if not CCID) then an endless busy loop is started inside libusb hotplug. Fixes: - Debian bug #812087 "pcscd takes 100 % cpu each time I insert a mass storage USB key" - Debian bug #821787 "cleanup libusb when open fails" - Ubuntu bug #1572004 "pcscd consumes 100% CPU" - Ubuntu bug #1551897 "Excessive CPU utilization" Thanks a lot to Stefan Bühler for the analysis and patch https://bugs.debian.org/821787" Thanks again! -- Dr. Ludovic Rousseau

