[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1271100621.20295.3397.camel@laptop>
Date: Mon, 12 Apr 2010 21:30:21 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Rik van Riel <riel@...hat.com>, Borislav Petkov <bp@...en8.de>,
Johannes Weiner <hannes@...xchg.org>,
KOSAKI Motohiro <kosaki.motohiro@...fujitsu.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Minchan Kim <minchan.kim@...il.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Lee Schermerhorn <Lee.Schermerhorn@...com>,
Nick Piggin <npiggin@...e.de>,
Andrea Arcangeli <aarcange@...hat.com>,
Hugh Dickins <hugh.dickins@...cali.co.uk>,
sgunderson@...foot.com
Subject: Re: [PATCH -v2] rmap: make anon_vma_prepare link in all the
anon_vmas of a mergeable VMA
On Mon, 2010-04-12 at 20:40 +0200, Peter Zijlstra wrote:
Hmm, if interleaved like so
> struct anon_vma *page_lock_anon_vma(struct page *page)
> {
> struct anon_vma *anon_vma;
> unsigned long anon_mapping;
page_remove_rmap()
anon_vma_unlink()
anon_vma_free()
So that the below will all observe the old page->mapping:
> rcu_read_lock();
> again:
> anon_mapping = (unsigned long)rcu_dereference(page->mapping);
> if ((anon_mapping & PAGE_MAPPING_FLAGS) != PAGE_MAPPING_ANON)
> goto out;
> anon_vma = (struct anon_vma *)(anon_mapping - PAGE_MAPPING_ANON);
>
> /*
> * The RCU read lock ensures we can safely dereference anon_vma
> * since it ensures the backing slab won't go away. It will however
> * not guarantee it's the right object.
> *
> * First take the anon_vma->lock, this will, per anon_vma_unlink()
> * avoid this anon_vma from being freed if it is a valid object.
> */
> spin_lock(&anon_vma->lock);
>
> /*
> * Secondly, we have to re-read page->mapping, so ensure it
> * has not changed, rely on spin_lock() being at least a
> * compiler barrier to force the re-read.
> */
> if (unlikely(page_rmapping(page) != anon_vma)) {
> spin_unlock(&anon_vma->lock);
> goto again;
> }
page_add_anon_rmap(), so that the page_mapped() test below would be
positive,
> /*
> * Ensure we read page->mapping before page->_mapcount,
> * orders against atomic_add_negative() in page_remove_rmap().
> */
> smp_rmb();
>
> /*
> * Finally check that the page is still mapped,
> * if not, this can't possibly be the right anon_vma.
> */
> if (!page_mapped(page))
> goto unlock;
We could here return a non-valid and already freed anon_vma.
> return anon_vma;
>
> unlock:
> spin_unlock(&anon_vma->lock);
> out:
> rcu_read_unlock();
> return NULL;
> }
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists