Re: [PATCH -v2] rmap: make anon_vma_prepare link in all the anon_vmasof a mergeable VMA

From: Linus Torvalds
Date: Fri Apr 09 2010 - 12:40:31 EST




On Fri, 9 Apr 2010, Borislav Petkov wrote:
>
> So I went and reapplied the three patches (3rd is the object_err export
> for SLUB debugging) on a new branch of today's git - same results, the
> same processes crap up in the WARN(!vma->anon_vma) check so it should be
> something else we're missing.
>
> More code staring later...

Can you try with _just_ my patch? Or add a

vma->anon_vma = merge_vma->anon_vma;

to Rik's "merge_vma" case in anon_vma_prepare().

Because I'm starign at Rik's patch, and one thing strikes me: it does that
"anon_vma_clone()" in anon_vma_prepare(), and maybe I'm blind, but I don't
see where that actually sets vma->anon_vma.

As far as I can tell, anon_vma_clone() was designed purely for the fork()
case, which has done

*new = *vma;

which will set new->anon_vma to the same vma. But Rik's patch never does
that for the anon_vma_prepare() case.

And maybe we should do it in anon_vma_clone() itself, just to make it
impossible to mistakenly leave it out, the way I think Rik's patch did.

Anyway, I'm still groggy from allt he flu medication, so take everything I
say with a grain of salt.

In fact, the more I look at this, the less I think I like Rik's patch in
the first place. I think the real bug that Rik tried to fix is that
apparently anon_vma_merge() doesn't necessarily merge everything right.
>From Rik's bug-explanation, step 5:

>> 5) vma_adjust calls anon_vma_merge, causing the anon_vma
>> chain of one of the VMAs to get nuked - with bad luck,
>> this is the original one, leaving just the new anon_vma
>> attached to the VMA

and I think that _this_ is the real bug to begin with. The real fix should
be in vma_adjust/anon_vma_merge, not in how we set up the anon_vma in the
first place. I do _not_ think we should require that we always merged
things at mmap() time, because we may _never_ be able to merge perfectly
(ie start out with to disjoing mmaps, and fill in the middle).

Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/