mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Li Zefan <lizf@cn.fujitsu.com>
To: Theodore Tso <tytso@mit.edu>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	Christoph Hellwig <hch@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>, Ingo Molnar <mingo@elte.hu>,
	linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-ext4@vger.kernel.org
Subject: [BUG] bugs in jbd2_dev_to_name() (was Re: [PATCH 00/11] [GIT PULL] more updates for the tag format)
Date: Fri, 19 Jun 2009 16:14:23 +0800	[thread overview]
Message-ID: <4A3B48DF.8080300@cn.fujitsu.com> (raw)
In-Reply-To: <20090611192037.GA5116@mit.edu>

Theodore Tso wrote:
> On Thu, Jun 11, 2009 at 07:14:36PM +0200, Frederic Weisbecker wrote:
>> For the filters, we could enter the text name which would be
>> internally converted into a dev_t, there should be no problem.
>>
>> Also the raw dev_t can be stored and then human-friendly printed on
>> print time.
>>
>> Both seem about trivial to add.
> 
> If someone wants to take this code and drop it into the core tracing
> code, please feel free.
> 

Just notice this code has been merge, but there are 2 bugs in it.

> 						- Ted
> 
> /* 
>  * jbd2_dev_to_name is a utility function used by the jbd2 and ext4 
>  * tracing infrastructure to map a dev_t to a device name.
>  *
>  * The caller should use rcu_read_lock() in order to make sure the
>  * device name stays valid until its done with it.  We use
>  * rcu_read_lock() as well to make sure we're safe in case the caller
>  * gets sloppy, and because rcu_read_lock() is cheap and can be safely
>  * nested.
>  */
> struct devname_cache {
> 	struct rcu_head	rcu;
> 	dev_t		device;
> 	char		devname[BDEVNAME_SIZE];
> };
> #define CACHE_SIZE_BITS 6
> static struct devname_cache *devcache[1 << CACHE_SIZE_BITS];
> static DEFINE_SPINLOCK(devname_cache_lock);
> 
> static void free_devcache(struct rcu_head *rcu)
> {
> 	kfree(rcu);
> }
> 
> const char *jbd2_dev_to_name(dev_t device)
> {
> 	int	i = hash_32(device, CACHE_SIZE_BITS);
> 	char	*ret;
> 	struct block_device *bd;
> 
> 	rcu_read_lock();
> 	if (devcache[i] && devcache[i]->device == device) {
> 		ret = devcache[i]->devname;
> 		rcu_read_unlock();
> 		return ret;

It doesn't seem safe to dereference @ret outside rcu read section.

> 	}
> 	rcu_read_unlock();
> 
> 	spin_lock(&devname_cache_lock);
> 	if (devcache[i]) {
> 		if (devcache[i]->device == device) {
> 			ret = devcache[i]->devname;
> 			spin_unlock(&devname_cache_lock);
> 			return ret;
> 		}
> 		call_rcu(&devcache[i]->rcu, free_devcache);
> 	}
> 	devcache[i] = kmalloc(sizeof(struct devname_cache), GFP_KERNEL);

kmalloc(GFP_KERNEL) called with spin_lock held..

> 	if (!devcache[i]) {
> 		spin_unlock(&devname_cache_lock);
> 		return "NODEV-ALLOCFAILURE"; /* Something non-NULL */
> 	}
> 	devcache[i]->device = device;
> 	bd = bdget(device);
> 	if (bd) {
> 		bdevname(bd, devcache[i]->devname);
> 		bdput(bd);
> 	} else
> 		__bdevname(device, devcache[i]->devname);
> 	ret = devcache[i]->devname;
> 	spin_unlock(&devname_cache_lock);
> 	return ret;
> }
> EXPORT_SYMBOL(jbd2_dev_to_name);

  reply	other threads:[~2009-06-19  8:13 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-10  5:42 [PATCH 00/11] [GIT PULL] more updates for the tag format Steven Rostedt
2009-06-10  5:42 ` [PATCH 01/11] tracing/events: convert block trace points to TRACE_EVENT(), fix Steven Rostedt
2009-06-10  5:42 ` [PATCH 02/11] tracing: add nsec2sec print formats Steven Rostedt
2009-06-10  5:42 ` [PATCH 03/11] tracing: convert lockdep lock_acquired trace point to use nsec2usec tag Steven Rostedt
2009-06-10  5:42 ` [PATCH 04/11] tracing: add major and minor tags for print format Steven Rostedt
2009-06-10  5:42 ` [PATCH 05/11] tracing: use << to print < instead of \< Steven Rostedt
2009-06-10  5:42 ` [PATCH 06/11] tracing: convert the block trace points to use the new tag format Steven Rostedt
2009-06-10  5:42 ` [PATCH 07/11] tracing: add test for strings in event " Steven Rostedt
2009-06-10  5:42 ` [PATCH 08/11] tracing: add func and symfunc to " Steven Rostedt
2009-06-10  7:48   ` Frederic Weisbecker
2009-06-10 12:55     ` Steven Rostedt
2009-06-10  5:42 ` [PATCH 09/11] tracing: check full name for field Steven Rostedt
2009-06-10  5:42 ` [PATCH 10/11] tracing: update sample code with new tag format Steven Rostedt
2009-06-10  5:42 ` [PATCH 11/11] tracing: move > to out of macros and into print statement Steven Rostedt
2009-06-10  9:26 ` [PATCH 00/11] [GIT PULL] more updates for the tag format Ingo Molnar
2009-06-10 11:11   ` Frédéric Weisbecker
2009-06-10 13:01     ` Theodore Tso
2009-06-10 13:49       ` Steven Rostedt
2009-06-10 14:39         ` Mathieu Desnoyers
2009-06-10 15:21           ` Steven Rostedt
2009-06-10 16:03         ` Theodore Tso
2009-06-10 16:17           ` Steven Rostedt
2009-06-11 13:03           ` Christoph Hellwig
2009-06-11 15:47             ` Theodore Tso
2009-06-11 17:14               ` Frederic Weisbecker
2009-06-11 19:20                 ` Theodore Tso
2009-06-19  8:14                   ` Li Zefan [this message]
2009-06-19 12:32                     ` [BUG] bugs in jbd2_dev_to_name() (was Re: [PATCH 00/11] [GIT PULL] more updates for the tag format) Theodore Tso
2009-06-22  1:36                       ` Li Zefan

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=4A3B48DF.8080300@cn.fujitsu.com \
    --to=lizf@cn.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=hch@infradead.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=tytso@mit.edu \
    /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

Powered by JetHome