From: Bart Van Assche <bart.vanassche@sandisk.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Johannes Thumshirn <jthumshirn@suse.de>,
James Bottomley <james.bottomley@hansenpartnership.com>,
Dan Williams <dan.j.williams@intel.com>,
"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>
Subject: Re: [PATCH 2/2] Restart list search after unlock in scsi_remove_target
Date: Wed, 4 Nov 2015 14:35:40 -0800 [thread overview]
Message-ID: <563A883C.9060501@sandisk.com> (raw)
In-Reply-To: <5633EA98.8050604@sandisk.com>
On 10/30/2015 03:09 PM, Bart Van Assche wrote:
> 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 is a slightly modified version of a patch from Christoph Hellwig
> (see also https://www.spinics.net/lists/linux-scsi/msg89416.html).
>
> Reported-by: Johannes Thumshirn <jthumshirn@suse.de>
> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Cc: Johannes Thumshirn <jthumshirn@suse.de>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: stable <stable@vger.kernel.org>
> ---
> drivers/scsi/scsi_sysfs.c | 16 ++++------------
> 1 file changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
> index b9fb61a..5a183d1 100644
> --- a/drivers/scsi/scsi_sysfs.c
> +++ b/drivers/scsi/scsi_sysfs.c
> @@ -1158,32 +1158,24 @@ 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
> - */
> +restart:
> spin_lock_irqsave(shost->host_lock, flags);
> list_for_each_entry(starget, &shost->__targets, siblings) {
> if (starget->reaped)
> continue;
> if (starget->dev.parent == dev || &starget->dev == dev) {
> - /* assuming new targets arrive at the end */
> kref_get(&starget->reap_ref);
> starget->reaped = true;
> spin_unlock_irqrestore(shost->host_lock, flags);
> - if (last)
> - scsi_target_reap(last);
> - last = starget;
> __scsi_remove_target(starget);
> - spin_lock_irqsave(shost->host_lock, flags);
> + scsi_target_reap(starget);
> + goto restart;
> }
> }
> spin_unlock_irqrestore(shost->host_lock, flags);
> -
> - if (last)
> - scsi_target_reap(last);
> }
> EXPORT_SYMBOL(scsi_remove_target);
(replying to my own e-mail)
Hello Christoph,
Is it OK for you if I mention you as author of this e-mail ?
Thanks,
Bart.
next prev parent reply other threads:[~2015-11-04 22:35 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-30 22:06 [PATCH 0/2] Fix a hard lockup in scsi_remove_target() Bart Van Assche
2015-10-30 22:08 ` [PATCH 1/2] Separate target visibility from reaped state information Bart Van Assche
2015-11-05 8:50 ` Christoph Hellwig
2015-10-30 22:09 ` [PATCH 2/2] Restart list search after unlock in scsi_remove_target Bart Van Assche
2015-11-04 22:35 ` Bart Van Assche [this message]
2015-11-04 22:44 ` James Bottomley
2015-11-04 23:20 ` Bart Van Assche
2015-11-16 17:57 ` Christoph Hellwig
2015-11-05 16:55 ` Dan Williams
2015-11-05 17:05 ` James Bottomley
2015-11-05 8:51 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=563A883C.9060501@sandisk.com \
--to=bart.vanassche@sandisk.com \
--cc=dan.j.williams@intel.com \
--cc=hch@lst.de \
--cc=james.bottomley@hansenpartnership.com \
--cc=jthumshirn@suse.de \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox