Re: [PATCH 4/5] always lock the root (oldest) anon_vma

From: Linus Torvalds
Date: Wed May 12 2010 - 18:29:26 EST




On Wed, 12 May 2010, Rik van Riel wrote:
>
> I suspect the atomic_dec_and_lock in the KVM code is being used
> to prevent the following race:
>
> 1) KSM code reduces the refcount to 0
>
> 2) munmap on other CPU frees the anon_vma
>
> 3) KSM code takes the anon_vma lock,
> which now lives in freed memory

Hmm. Well, if it were just about the lock, then that would be fine. That's
why we do the whole anon_vma RCU freeing dance, after all.

But I guess you're right - although not because of the lock. You're right
because it would be a double-free - both parties would decide that they
can free the damn thing, because it's not a pure atomic refcount, it's a
"refcount or list_empty()" thing.

If _everybody_ was using the refcount, we could just do the
atomic_dec_and_test(). But they aren't. So yeah, I guess we do want that
nasty dec-and-lock version.

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/