public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Russell King <rmk+lkml@arm.linux.org.uk>
To: Pierre Ossman <drzeus-list@drzeus.cx>,
	Al Viro <viro@ftp.uk.linux.org>, Jens Axboe <axboe@suse.de>
Cc: Mikkel Erup <mikkelerup@yahoo.com>, Greg KH <greg@kroah.com>,
	linux-kernel@vger.kernel.org, Andrew Morton <akpm@osdl.org>
Subject: Re: sdhci driver produces kernel oops on ejecting the card
Date: Fri, 7 Apr 2006 15:40:46 +0100	[thread overview]
Message-ID: <20060407144046.GA21049@flint.arm.linux.org.uk> (raw)
In-Reply-To: <4436273A.9000504@drzeus.cx>

On Fri, Apr 07, 2006 at 10:47:54AM +0200, Pierre Ossman wrote:
> Mikkel Erup wrote:
> > 
> > It happens with 2.6.16-git20 as well.
> > Attached are the log file and kernel .config
> > 
> 
> Since it ooopses during umount, I'm guessing that it's a problem
> somewhere in mmc_block. I'll try to get some time to look closer at it
> during the weekend. Perhaps Russell has some idea until then?

$ grep -n driverfs_dev block/genhd.c
558:    physdev = disk->driverfs_dev;
$

Hmm, okay, genhd contains a reference to a device object, but there's
no sign of _any_ refcounting in sight.

What's happening is that the MMC card block device is setup and registered
with genhd.  We set md->disk->driverfs_dev to point at the owning device
structure.

This generates a uevent, which causes disk->driverfs_dev to be dereferenced.
All fine here.  We mount the partition, which causes another uevent to be
generated, again dereferencing disk->driverfs_dev.

If we remove the MMC card, we destroy the MMC card block device.  This
seems to generate another uevent for the block device.  At this point,
the counted references to the MMC card block device fall to zero.

But wait!  There's still uncounted disk->driverfs_dev reference waiting
for...

You unmount the partition.  This calls block_uevent, which dereferences
disk->driverfs_dev.  You know what happens now.

The levels above genhd can't do the refcounting because they don't know
when stuff has finished with driverfs_dev.  So the only place for sane
refcounting seems to be genhd.c, as per the patch below.

Comments?

diff -up -x BitKeeper -x ChangeSet -x SCCS -x _xlk -x *.orig -x *.rej -x .git a/block/genhd.c b/block/genhd.c
--- a/block/genhd.c	Sat Feb 18 10:31:37 2006
+++ b/block/genhd.c	Fri Apr  7 15:22:21 2006
@@ -262,6 +262,7 @@ static int exact_lock(dev_t dev, void *d
  */
 void add_disk(struct gendisk *disk)
 {
+	get_device(disk->driverfs_dev);
 	disk->flags |= GENHD_FL_UP;
 	blk_register_region(MKDEV(disk->major, disk->first_minor),
 			    disk->minors, NULL, exact_match, exact_lock, disk);
@@ -507,6 +508,7 @@ static struct attribute * default_attrs[
 static void disk_release(struct kobject * kobj)
 {
 	struct gendisk *disk = to_disk(kobj);
+	put_device(disk->driverfs_dev);
 	kfree(disk->random);
 	kfree(disk->part);
 	free_disk_stats(disk);


-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core

  reply	other threads:[~2006-04-07 14:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-02 19:48 sdhci driver produces kernel oops on ejecting the card Mikkel Erup
2006-04-02 20:29 ` Greg KH
2006-04-03 22:19   ` Mikkel Erup
2006-04-07  8:47     ` Pierre Ossman
2006-04-07 14:40       ` Russell King [this message]
2006-04-07 20:29         ` Mikkel Erup
  -- strict thread matches above, loose matches on Subject: below --
2006-04-11 19:43 Mikkel Erup
2006-04-12  9:30 ` Russell King

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=20060407144046.GA21049@flint.arm.linux.org.uk \
    --to=rmk+lkml@arm.linux.org.uk \
    --cc=akpm@osdl.org \
    --cc=axboe@suse.de \
    --cc=drzeus-list@drzeus.cx \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikkelerup@yahoo.com \
    --cc=viro@ftp.uk.linux.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