]> git.baikalelectronics.ru Git - kernel.git/commit
usb-storage: fix deadlock involving host lock and scsi_done
authorAlan Stern <stern@rowland.harvard.edu>
Wed, 26 Jul 2017 15:49:19 +0000 (11:49 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 30 Jul 2017 14:18:27 +0000 (07:18 -0700)
commit1d9bafe1bc31000c2894ef4154877752c35dd551
tree2e05e2175a5d5d1597ccaf17f1f4344dc680e865
parent48a8c3f83782f8ec35e9eb2f17cfd36d2f9f56a9
usb-storage: fix deadlock involving host lock and scsi_done

Christoph Hellwig says that since version 4.12, the kernel switched to
using blk-mq by default.  The old code used a softirq for handling
request completions, but blk-mq can handle completions in the caller's
context.  This may cause a problem for usb-storage, because it invokes
the ->scsi_done callback while holding the host lock, and the
completion routine sometimes tries to acquire the same lock (when
running the error handler, for example).

The consequence is that the existing code will sometimes deadlock upon
error completion of a SCSI command (with a lockdep warning).

This is easy enough to fix, since usb-storage doesn't really need to
hold the host lock while the callback runs.  It was simpler to write
it that way, but moving the call outside the locked region is pretty
easy and there's no downside.  That's what this patch does.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Reported-and-tested-by: Arthur Marsh <arthur.marsh@internode.on.net>
CC: Christoph Hellwig <hch@lst.de>
CC: <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/storage/usb.c