public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Akinobu Mita <mita@miraclelinux.com>
Cc: linux-kernel@vger.kernel.org, akpm@osdl.org,
	Patrick Mochel <mochel@osdl.org>
Subject: Re: [patch 1/2] kref: detect kref_put() with unreferenced object
Date: Tue, 25 Apr 2006 17:26:28 -0700	[thread overview]
Message-ID: <20060426002628.GB24343@kroah.com> (raw)
In-Reply-To: <20060425082359.767915000@localhost.localdomain>

On Tue, Apr 25, 2006 at 04:21:38PM +0800, Akinobu Mita wrote:
> This patch adds warning to detect kref_put() with unreferenced object.
> 
> The idea of detection kref_put() with unreferenced object was stolen
> from BUG_ON()es in blocks/ll_rw_blk.c and fs/bio.c
> 
> ll_rw_blk.c:    BUG_ON(atomic_read(&ioc->refcount) == 0);
> 
> bio.c:          BIO_BUG_ON(!atomic_read(&bio->bi_cnt));
> 
> But the kref counter usually does not fall to zero. Because kref is
> trying to reduce the number of atomic_dec_and_test()
> 
> So this patch also set kref counter to zero here:
> 
> +	if (atomic_read(&kref->refcount) == 1)
> +		atomic_set(&kref->refcount, 0);

I really don't see how this is going to make it easier to debug
anything.  Remember, when a kref goes to 0, it is automatically freed.
So any code that tries to use it afterward just dies a horrible death,
if CONFIG_DEBUG_SLAB is enabled.

And please be careful, you can't replace all usages of atomic_t counters
in the kernel with krefs...

thanks,

greg k-h

  reply	other threads:[~2006-04-26  0:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-25  8:21 [patch 0/2] kref debugging (retry) Akinobu Mita
2006-04-25  8:21 ` [patch 1/2] kref: detect kref_put() with unreferenced object Akinobu Mita
2006-04-26  0:26   ` Greg KH [this message]
2006-04-26  2:17     ` Akinobu Mita
2006-04-25  8:21 ` [patch 2/2] kref: kref debugging config option Akinobu Mita
2006-04-26  0:24   ` Greg KH

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=20060426002628.GB24343@kroah.com \
    --to=greg@kroah.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mita@miraclelinux.com \
    --cc=mochel@osdl.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