• Alan Stern's avatar
    usb-storage: fix deadlock involving host lock and scsi_done · 8b52291a
    Alan Stern authored
    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: default avatarAlan Stern <stern@rowland.harvard.edu>
    Reported-and-tested-by: default avatarArthur Marsh <arthur.marsh@internode.on.net>
    CC: Christoph Hellwig <hch@lst.de>
    CC: <stable@vger.kernel.org>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    8b52291a
usb.c 31.2 KB