From: Tomas Henzl <thenzl@redhat.com>
To: Bart Van Assche <bvanassche@acm.org>
Cc: "'linux-scsi@vger.kernel.org'" <linux-scsi@vger.kernel.org>,
Stanislaw Gruszka <sgruszka@redhat.com>,
Mike Christie <michaelc@cs.wisc.edu>
Subject: Re: [RFC] How to fix an async scan - rmmod race?
Date: Fri, 06 Apr 2012 15:13:33 +0200 [thread overview]
Message-ID: <4F7EEBFD.8000809@redhat.com> (raw)
In-Reply-To: <4F7EC1F8.9030706@redhat.com>
On 04/06/2012 12:14 PM, Tomas Henzl wrote:
> On 04/06/2012 11:39 AM, Bart Van Assche wrote:
>> On 04/05/12 13:58, Tomas Henzl wrote:
>>
>>> When the async scan is protected this way a further protection via ref. count is no more needed
>>> so remove it
>>> diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
>>> index 29c4c04..be9e6fe 100644
>>> --- a/drivers/scsi/scsi_scan.c
>>> +++ b/drivers/scsi/scsi_scan.c
>>> @@ -1743,10 +1743,9 @@ static struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost)
>>>
>>> data = kmalloc(sizeof(*data), GFP_KERNEL);
>>> if (!data)
>>> - goto err;
>>> - data->shost = scsi_host_get(shost);
>>> - if (!data->shost)
>>> - goto err;
>>> + return NULL;
>>> +
>>> + data->shost = shost;
>>> init_completion(&data->prev_finished);
>>>
>>> mutex_lock(&shost->scan_mutex);
>> Maybe it's better to leave the scsi_host_get() / scsi_host_put() pair in
>> scsi_prep_async_scan() and scsi_finish_async_scan(). Let's have a look
>> at the following code in scsi_finish_async_scan():
>>
>> spin_lock_irqsave(shost->host_lock, flags);
>> shost->async_scan = 0;
>> spin_unlock_irqrestore(shost->host_lock, flags);
>>
>> If the context that is waiting for shost->async_scan wouldn't lock
>> shost->host_lock after having observed that shost->async_scan became
>> zero then shost->host_lock could already have been freed before
>> scsi_finish_async_scan() has unlocked that spin lock. Personally I
>> prefer to avoid having such subtle dependencies between the async
>> scanning code and the context waiting for it to finish.
Actually that would be worse than to depend on the shost->host_lock
while (shost->async_scan)
msleep(10);
spin_lock_irqsave(shost->host_lock, flags); /* hi this spinlock is needed for async scan test above */
We can add this comment ^ ,or add locking to the while loop.
Otherwise we will have this in scsi_finish_async_scan
+ spin_lock_irqsave(shost->host_lock, flags);
+ shost->async_scan = 0;
+ spin_unlock_irqrestore(shost->host_lock, flags);
scsi_host_put(shost);
...}
This means that after scsi_remove_host is left and the driver rmmoded we call
scsi_host_put which in the end calls scsi_host_dev_release and this function tries to use
the now invalid host_template functions again.
> It's also my preference It's not built in for purpose, I only haven't
> noticed it :)
> Thanks for the advice.
>
> Tomas
>
>
>> Bart.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2012-04-06 13:13 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-05 13:58 [RFC] How to fix an async scan - rmmod race? Tomas Henzl
2012-04-05 15:57 ` Mike Christie
2012-04-05 16:05 ` Mike Christie
2012-04-05 18:00 ` Bart Van Assche
2012-04-05 21:29 ` Mike Christie
2012-04-06 9:24 ` Bart Van Assche
2012-04-06 17:22 ` Mike Christie
2012-04-06 18:37 ` Bart Van Assche
2012-04-11 21:46 ` Mike Christie
2012-04-06 9:54 ` Tomas Henzl
2012-04-06 15:20 ` James Bottomley
2012-04-06 16:15 ` Bart Van Assche
2012-04-06 16:35 ` James Bottomley
2012-04-06 17:01 ` Bart Van Assche
2012-04-06 17:15 ` James Bottomley
2012-04-06 17:59 ` Bart Van Assche
2012-04-08 17:38 ` Bart Van Assche
2012-04-11 18:17 ` Mike Christie
2012-04-11 18:30 ` Mike Christie
2012-04-11 19:47 ` Bart Van Assche
2012-04-11 22:28 ` Mike Christie
2012-04-12 10:48 ` Bart Van Assche
2012-04-06 9:39 ` Bart Van Assche
2012-04-06 10:14 ` Tomas Henzl
2012-04-06 13:13 ` Tomas Henzl [this message]
2012-04-06 14:38 ` Bart Van Assche
2012-04-06 15:32 ` Tomas Henzl
2012-04-12 12:48 ` [RFC] How to fix an async scan - rmmod race? try_module_get Tomas Henzl
2012-04-18 16:48 ` [RFC] How to fix an async scan - 'rmmod --wait' race? Tomas Henzl
2012-04-18 18:18 ` Bart Van Assche
2012-05-17 8:42 ` James Bottomley
2012-05-17 8:55 ` Bart Van Assche
2012-05-17 9:01 ` James Bottomley
2012-05-17 14:51 ` Tomas Henzl
2012-05-22 10:05 ` James Bottomley
2012-05-25 15:13 ` Tomas Henzl
2012-05-25 18:46 ` Dan Williams
2012-05-28 11:58 ` Tomas Henzl
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=4F7EEBFD.8000809@redhat.com \
--to=thenzl@redhat.com \
--cc=bvanassche@acm.org \
--cc=linux-scsi@vger.kernel.org \
--cc=michaelc@cs.wisc.edu \
--cc=sgruszka@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).