linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Dave Chinner <david@fromorbit.com>
Cc: Eric Paris <eparis@redhat.com>,
	linux-kernel@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, hch@infradead.org,
	zohar@us.ibm.com, warthog9@kernel.org, jmorris@namei.org,
	kyle@mcmartin.ca, hpa@zytor.com, akpm@linux-foundation.org,
	torvalds@linux-foundation.org, mingo@elte.hu,
	viro@zeniv.linux.org.uk
Subject: Re: [PATCH 5/6] IMA: use rbtree instead of radix tree for inode information cache
Date: Wed, 20 Oct 2010 13:31:09 +0200	[thread overview]
Message-ID: <1287574269.3488.11.camel@twins> (raw)
In-Reply-To: <20101019231747.GC12506@dastard>

On Wed, 2010-10-20 at 10:17 +1100, Dave Chinner wrote:
> On Tue, Oct 19, 2010 at 06:58:39PM -0400, Eric Paris wrote:
> > @@ -36,12 +63,11 @@ struct ima_iint_cache *ima_iint_find_get(struct inode *inode)
> >  	struct ima_iint_cache *iint;
> >  
> >  	rcu_read_lock();
> > -	iint = radix_tree_lookup(&ima_iint_store, (unsigned long)inode);
> > -	if (!iint)
> > -		goto out;
> > -	kref_get(&iint->refcount);
> > -out:
> > +	iint = __ima_iint_find(inode);
> > +	if (iint)
> > +		kref_get(&iint->refcount);
> >  	rcu_read_unlock();
> > +
> 
> This is wrong - the rbtree is protected only by the ima_iint_lock(),
> not RCU. Hence you can't do lockless lookups on an rbtree in this
> manner as they will race with inserts and deletes.

Correct, what can be made to work is combine RCU with a seqlock. Retry
the lookup using read_seqretry(), RCU here helps to ensure you're not
stepping on already freed memory.


So, tree modification does:

  write_seqlock();
  /* frob RB-tree, using call_rcu() for frees where needed */
  write_sequnlock();

Lookup does:

  unsigned seq;

  rcu_read_lock()
again;
  seq = read_seqbegin();

  /* RB-tree lookup */

  if (read_seqretry(seq))
    goto again;

  rcu_read_unlock();

  return obj;
  

  reply	other threads:[~2010-10-20 11:31 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-19 22:58 [PATCH 1/6] IMA: move read/write counters into struct inode Eric Paris
2010-10-19 22:58 ` [PATCH 2/6] IMA: drop the inode opencount since it isn't needed for operation Eric Paris
2010-10-19 22:58 ` [PATCH 3/6] IMA: use unsigned int instead of long for counters Eric Paris
2010-10-19 22:58 ` [PATCH 4/6] IMA: only allocate iint when needed Eric Paris
2010-10-20  3:53   ` Al Viro
2010-10-19 22:58 ` [PATCH 5/6] IMA: use rbtree instead of radix tree for inode information cache Eric Paris
2010-10-19 23:17   ` Dave Chinner
2010-10-20 11:31     ` Peter Zijlstra [this message]
2010-10-20 22:05       ` Dave Chinner
2010-10-20 22:22         ` Linus Torvalds
2010-10-20 22:47           ` Trond Myklebust
2010-10-21  0:58             ` Linus Torvalds
2010-10-21  2:17               ` Dave Chinner
2010-10-19 22:58 ` [PATCH 6/6] IMA: use i_writecount rather than a private counter Eric Paris
2010-10-20  0:25 ` [PATCH 1/6] IMA: move read/write counters into struct inode Linus Torvalds
2010-10-23  3:01   ` Eric Paris
2010-10-24  6:52     ` Mimi Zohar

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=1287574269.3488.11.camel@twins \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@fromorbit.com \
    --cc=eparis@redhat.com \
    --cc=hch@infradead.org \
    --cc=hpa@zytor.com \
    --cc=jmorris@namei.org \
    --cc=kyle@mcmartin.ca \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=warthog9@kernel.org \
    --cc=zohar@us.ibm.com \
    /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).