From: Stanislaw Gruszka <stf_xl@wp.pl>
To: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Cc: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: Re: Bad module reference counter
Date: Fri, 20 Feb 2009 11:45:02 +0100 [thread overview]
Message-ID: <200902201145.02308.stf_xl@wp.pl> (raw)
In-Reply-To: <200902191749.52740.bzolnier@gmail.com>
Thursday 19 February 2009 17:49:52 Bartlomiej Zolnierkiewicz napisał(a):
> > > Seems like ide_device_put() needs the same module_refcount() check that
> > > is present in scsi_device_put() so removal of device driver won't trigger
> > > a spurious module_put() on a host driver?
> >
> > I little surprise about scsi code (linux-scsi ML CC). Is comment inside
> > scsi_device_put() function correct? Why scsi_device_get() not check
> > try_module_get() return value? And most importand: there is reference
> > counter check before put, so it can be 0, but data does it protect is in
> > use ?
Any comments?
> Uh... we will need some more intrusive changes to the reference counting
> to fix it -- like to replace idkp->kref by idkp->dev and make drive->gendev
> a parent of it (so only after the final put on ->dev ->gendev can go away).
>
> [ IOW we need to have some changes similar to those done in sd.c by:
> commit 6bdaa1f17dd32ec62345c7b57842f53e6278a2fa
> and later by:
> commit ee959b00c335d7780136c5abda37809191fe52c3 ]
>
> > There is no oops with my workaround, when I just remove ide_disk_put() from
>
> I suppose that after ide_disk_put() removal ide_disk_release() is simply
> never called... ;)
>
> > ide_gd_remove(). It's strange why there is lack of symmetrical _put/_get calls,
> > ide_gd_probe() has no call to ide_disk_get().
>
> We have kref_init() in ide_disk_probe(), so there is no need for it
> and we also don't want to hold an extra reference on host driver...
Looks that using ->dev insted of ->kref will do the work. But perhaps less
intrusive fix, like check kref in ide_disk_put() would be better solution.
I tested below patch and everythings is fine.
diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c
index 7857b20..598f21b 100644
--- a/drivers/ide/ide-gd.c
+++ b/drivers/ide/ide-gd.c
@@ -48,8 +48,8 @@ static void ide_disk_put(struct ide_disk_obj *idkp)
ide_drive_t *drive = idkp->drive;
mutex_lock(&ide_disk_ref_mutex);
- kref_put(&idkp->kref, ide_disk_release);
- ide_device_put(drive);
+ if (!kref_put(&idkp->kref, ide_disk_release))
+ ide_device_put(drive);
mutex_unlock(&ide_disk_ref_mutex);
}
If this patch is ok and dropping kref to dev is not planed currently, maybe
I'll send "official" patch with ide-gd fix and for other devices types.
Regards
Stanislaw Gruszka
--
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:[~2009-02-20 10:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-11 9:32 Bad module reference counter Stanislaw Gruszka
2009-02-18 21:25 ` Bartlomiej Zolnierkiewicz
2009-02-19 12:48 ` Stanislaw Gruszka
2009-02-19 16:49 ` Bartlomiej Zolnierkiewicz
2009-02-20 10:45 ` Stanislaw Gruszka [this message]
2009-02-23 22:36 ` Bartlomiej Zolnierkiewicz
2009-02-25 11:00 ` Stanislaw Gruszka
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=200902201145.02308.stf_xl@wp.pl \
--to=stf_xl@wp.pl \
--cc=bzolnier@gmail.com \
--cc=linux-ide@vger.kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).