* [BUG] bugs in jbd2_dev_to_name() (was Re: [PATCH 00/11] [GIT PULL] more updates for the tag format)
[not found] ` <20090611192037.GA5116@mit.edu>
@ 2009-06-19 8:14 ` Li Zefan
2009-06-19 12:32 ` Theodore Tso
0 siblings, 1 reply; 3+ messages in thread
From: Li Zefan @ 2009-06-19 8:14 UTC (permalink / raw)
To: Theodore Tso
Cc: Frederic Weisbecker, Christoph Hellwig, Steven Rostedt,
Ingo Molnar, linux-kernel, Andrew Morton, linux-ext4
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);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG] bugs in jbd2_dev_to_name() (was Re: [PATCH 00/11] [GIT PULL] more updates for the tag format)
2009-06-19 8:14 ` [BUG] bugs in jbd2_dev_to_name() (was Re: [PATCH 00/11] [GIT PULL] more updates for the tag format) Li Zefan
@ 2009-06-19 12:32 ` Theodore Tso
2009-06-22 1:36 ` Li Zefan
0 siblings, 1 reply; 3+ messages in thread
From: Theodore Tso @ 2009-06-19 12:32 UTC (permalink / raw)
To: Li Zefan
Cc: Frederic Weisbecker, Christoph Hellwig, Steven Rostedt,
Ingo Molnar, linux-kernel, Andrew Morton, linux-ext4
On Fri, Jun 19, 2009 at 04:14:23PM +0800, Li Zefan wrote:
> > 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.
Note the comments at the beginning of the function:
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.
I suppose I should change the wording to indicate that it adds a bit
more safety (as in, the crash won't happen inside this function, but
as far as the caller is concerned, all bets are off!)
> > 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..
Good catch, thanks. I'll get a patch in to fix this.
- Ted
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG] bugs in jbd2_dev_to_name() (was Re: [PATCH 00/11] [GIT PULL] more updates for the tag format)
2009-06-19 12:32 ` Theodore Tso
@ 2009-06-22 1:36 ` Li Zefan
0 siblings, 0 replies; 3+ messages in thread
From: Li Zefan @ 2009-06-22 1:36 UTC (permalink / raw)
To: Theodore Tso, Li Zefan, Frederic Weisbecker, Christoph Hellwig,
Steven Rostedt, I
Theodore Tso wrote:
> On Fri, Jun 19, 2009 at 04:14:23PM +0800, Li Zefan wrote:
>>> 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.
>
> Note the comments at the beginning of the function:
>
Ah, I overlooked the comments.
But the patch that adds rcu locking around trace event prints
never gets merged:
http://lkml.org/lkml/2009/4/15/549
Steven?
> 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.
>
> I suppose I should change the wording to indicate that it adds a bit
> more safety (as in, the crash won't happen inside this function, but
> as far as the caller is concerned, all bets are off!)
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-06-22 1:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20090610054206.510574695@goodmis.org>
[not found] ` <20090610092644.GA20889@elte.hu>
[not found] ` <c62985530906100411o5a178352n53f7d247f6e9dba9@mail.gmail.com>
[not found] ` <20090610130127.GA6647@mit.edu>
[not found] ` <alpine.DEB.2.00.0906100911190.30552@gandalf.stny.rr.com>
[not found] ` <20090610160303.GA10240@mit.edu>
[not found] ` <20090611130318.GB14220@infradead.org>
[not found] ` <20090611154751.GD9275@mit.edu>
[not found] ` <20090611171434.GA6011@nowhere>
[not found] ` <20090611192037.GA5116@mit.edu>
2009-06-19 8:14 ` [BUG] bugs in jbd2_dev_to_name() (was Re: [PATCH 00/11] [GIT PULL] more updates for the tag format) Li Zefan
2009-06-19 12:32 ` Theodore Tso
2009-06-22 1:36 ` Li Zefan
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).