From: Tejun Heo <tj@kernel.org>
To: "Jun'ichi Nomura" <j-nomura@ce.jp.nec.com>
Cc: Naveen Goswamy <naveen.goswamy@polymtl.ca>,
Jens Axboe <axboe@kernel.dk>,
James Bottomley <James.Bottomley@HansenPartnership.com>,
Stefan Richter <stefanr@s5r6.in-berlin.de>,
Dave Jones <davej@redhat.com>,
linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: Re: Kernel crashing on eject SD card
Date: Thu, 16 Feb 2012 08:36:30 -0800 [thread overview]
Message-ID: <20120216163630.GH24986@google.com> (raw)
In-Reply-To: <4F3C5B4E.3080606@ce.jp.nec.com>
Hello,
On Thu, Feb 16, 2012 at 10:26:38AM +0900, Jun'ichi Nomura wrote:
> >> +int invalidate_partitions(struct gendisk *disk, struct block_device *bdev)
> >> +{
> >> + int res;
> >> +
> >> + res = drop_partitions(disk, bdev);
> >> + if (res)
> >> + return res;
> >> +
> >
> > Hmmm... shouldn't we have set_capacity(disk, 0) here?
>
> Added.
> I wasn't sure whether I should leave it to drivers.
The problem is that we shouldn't call into drivers without first
opening the device, so....
> But it seems capacity 0 for ENOMEDIUM device is reasonable.
Yeah, I *think* it should be okay.
> >> + check_disk_size_change(disk, bdev);
> >> + bdev->bd_invalidated = 0;
> >> + /* tell userspace that the media / partition table may have changed */
> >> + kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
> >
> > Also, we really shouldn't be generating KOBJ_CHANGE after every
> > -ENOMEDIUM open. This can easily lead to infinite loop. We should
> > generate this iff we actually dropped partitions && modified the size.
>
> invalidate_partitions() is called only when bd_invalidated is set.
> So KOBJ_CHANGE is not raised for every ENOMEDIUM open.
Ah, okay.
> I put it explicit in the function to make it safer for
> possible misuse.
>
> How about this?
>
> ---------------------------------------------------------
> Do not call drivers when invalidating partitions for -ENOMEDIUM
>
> When a scsi driver returns -ENOMEDIUM for open(),
> __blkdev_get() calls rescan_partitions(), which ends up calling
> sd_revalidate_disk() without getting a refcount of scsi_device.
>
> That could lead to oops like this:
>
> process A process B
> ----------------------------------------------
> sys_open
> __blkdev_get
> sd_open
> returns -ENOMEDIUM
> scsi_remove_device
> <scsi_device torn down>
> rescan_partitions
> sd_revalidate_disk
> <oops>
>
> Oopses are reported here:
> http://marc.info/?l=linux-scsi&m=132388619710052
>
> This patch separates the partition invalidation from rescan_partitions()
> and use it for -ENOMEDIUM case.
Yeah, this looks good to me.
Thank you.
--
tejun
next prev parent reply other threads:[~2012-02-16 16:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-08 0:19 Kernel crashing on eject SD card Naveen Goswamy
2012-02-12 21:08 ` Stefan Richter
2012-02-12 21:20 ` Stefan Richter
2012-02-13 1:46 ` Naveen Goswamy
2012-02-13 2:18 ` Dave Jones
2012-02-13 17:40 ` Naveen Goswamy
2012-02-14 11:14 ` Jun'ichi Nomura
2012-02-14 13:31 ` Stefan Richter
2012-02-14 16:28 ` Tejun Heo
2012-02-15 2:56 ` Jun'ichi Nomura
2012-02-15 17:26 ` Tejun Heo
2012-02-16 1:26 ` Jun'ichi Nomura
2012-02-16 16:36 ` Tejun Heo [this message]
2012-03-01 18:58 ` Luis Henriques
2012-03-02 0:12 ` Jun'ichi Nomura
2012-03-02 9:35 ` Luis Henriques
2012-03-02 9:41 ` Jens Axboe
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=20120216163630.GH24986@google.com \
--to=tj@kernel.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=axboe@kernel.dk \
--cc=davej@redhat.com \
--cc=j-nomura@ce.jp.nec.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=naveen.goswamy@polymtl.ca \
--cc=stefanr@s5r6.in-berlin.de \
/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).