Commit 40998193 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by James Bottomley

scsi: restart list search after unlock in scsi_remove_target

When dropping a lock while iterating a list we must restart the search
as other threads could have manipulated the list under us.  Without this
we can get stuck in an endless loop.  This bug was introduced by

commit bc3f02a7
Author: Dan Williams <>
Date:   Tue Aug 28 22:12:10 2012 -0700

    [SCSI] scsi_remove_target: fix softlockup regression on hot remove

Which was itself trying to fix a reported soft lockup issue

However, we believe even with this revert of the original patch, the soft
lockup problem has been fixed by

commit f2495e22
Author: James Bottomley <>
Date:   Tue Jan 21 07:01:41 2014 -0800

    [SCSI] dual scan thread bug fix

Thanks go to Dan Williams <> for tracking all this
prior history down.
Reported-by: default avatarJohannes Thumshirn <>
Signed-off-by: default avatarChristoph Hellwig <>
Tested-by: default avatarJohannes Thumshirn <>
Reviewed-by: default avatarJohannes Thumshirn <>
Fixes: bc3f02a7
Signed-off-by: default avatarJames Bottomley <>
parent a82544c7
......@@ -1158,31 +1158,23 @@ static void __scsi_remove_target(struct scsi_target *starget)
void scsi_remove_target(struct device *dev)
struct Scsi_Host *shost = dev_to_shost(dev->parent);
struct scsi_target *starget, *last = NULL;
struct scsi_target *starget;
unsigned long flags;
/* remove targets being careful to lookup next entry before
* deleting the last
spin_lock_irqsave(shost->host_lock, flags);
list_for_each_entry(starget, &shost->__targets, siblings) {
if (starget->state == STARGET_DEL)
if (starget->dev.parent == dev || &starget->dev == dev) {
/* assuming new targets arrive at the end */
spin_unlock_irqrestore(shost->host_lock, flags);
if (last)
last = starget;
spin_lock_irqsave(shost->host_lock, flags);
goto restart;
spin_unlock_irqrestore(shost->host_lock, flags);
if (last)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment