Re: [PATCH 02/11] mm,migration: Do not try to migrate unmapped anonymous pages

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: KAMEZAWA Hiroyuki
Date: Sunday, March 14, 2010 - 11:44 pm

On Mon, 15 Mar 2010 15:28:15 +0900
Minchan Kim <minchan.kim@gmail.com> wrote:

I think this patch is not complete. 
I guess this patch in [1/11] is trigger for the race.
==
+
+	/* Drop an anon_vma reference if we took one */
+	if (anon_vma && atomic_dec_and_lock(&anon_vma->migrate_refcount, &anon_vma->lock)) {
+		int empty = list_empty(&anon_vma->head);
+		spin_unlock(&anon_vma->lock);
+		if (empty)
+			anon_vma_free(anon_vma);
+	}
==
If my understainding in above is correct, this "modify" freed anon_vma.
Then, use-after-free happens. (In old implementation, there are no refcnt,
so, there is no use-after-free ops.)


So, what I can think of now is a patch like following is necessary.

==
static inline struct anon_vma *anon_vma_alloc(void)
{
        struct anon_vma *anon_vma;
        anon_vma = kmem_cache_alloc(anon_vma_cachep, GFP_KERNEL);
        atomic_set(&anon_vma->refcnt, 1);
}

void anon_vma_free(struct anon_vma *anon_vma)
{
        /*
         * This called when anon_vma is..
         * - anon_vma->vma_list becomes empty.
         * - incremetned refcnt while migration, ksm etc.. is dropped.
         * - allocated but unused.
         */
        if (atomic_dec_and_test(&anon_vma->refcnt))
                kmem_cache_free(anon_vma_cachep, anon_vma);
}
==
Then all things will go simple. 
Overhead is concern but list_empty() helps us much.

Thanks,
-Kame




--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., KAMEZAWA Hiroyuki, (Sun Mar 14, 10:34 pm)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., KAMEZAWA Hiroyuki, (Sun Mar 14, 11:44 pm)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., KAMEZAWA Hiroyuki, (Mon Mar 15, 12:09 am)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., KAMEZAWA Hiroyuki, (Mon Mar 15, 4:49 pm)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., KAMEZAWA Hiroyuki, (Tue Mar 16, 7:12 pm)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., KAMEZAWA Hiroyuki, (Tue Mar 16, 8:15 pm)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., KAMEZAWA Hiroyuki, (Tue Mar 16, 9:19 pm)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., Christoph Lameter, (Wed Mar 17, 9:41 am)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., KAMEZAWA Hiroyuki, (Wed Mar 17, 5:30 pm)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., KAMEZAWA Hiroyuki, (Thu Mar 25, 2:02 am)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., KAMEZAWA Hiroyuki, (Thu Mar 25, 2:08 am)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., KAMEZAWA Hiroyuki, (Thu Mar 25, 2:41 am)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., KAMEZAWA Hiroyuki, (Thu Mar 25, 3:12 am)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., Christoph Lameter, (Thu Mar 25, 7:35 am)
Re: [PATCH 02/11] mm,migration: Do not try to migrate unma ..., KAMEZAWA Hiroyuki, (Thu Mar 25, 5:58 pm)