Re: [PATCH -next] mm,vmacache: also flush cache for VM_CLONE

From: Davidlohr Bueso
Date: Thu Mar 13 2014 - 15:04:28 EST


On Thu, 2014-03-13 at 16:32 +0100, Oleg Nesterov wrote:
> On 03/13, Oleg Nesterov wrote:
> >
> > Yes. But it seems that use_mm() and unuse_mm() should invalidate vmacache too.
> >
> > Suppose that a kernel thread T does, say,
> >
> > use_mm(foreign_mm);
> > get_user(...);
> > unuse_mm();
> >
> > This can trigger a fault and populate T->vmacache[]. If this code is called
> > again vmacache_find() can use the stale entries.
> >
> > Or, assuming that only a kernel thread can do use_mm(), we can change
> > vmacache_valid() to also check !PF_KTHREAD.
>
> Yes, I think we should check PF_KTHREAD, because
>
> > Hmm. Another problem is that use_mm() doesn't take ->mmap_sem and thus
> > it can race with vmacache_flush_all()...
>
> this also closes this race. use_mm() users should not use vmacache at all.
>
> > Finally. Shouldn't vmacache_update() check current->mm == mm as well?
> > What if access_remote_vm/get_user_pages trigger find_vma() ??? Unless
> > I missed something this is not theoretical at all and can lead to the
> > corrupted vmacache, no?
>
> Looks like a real problem or I am totally confused. I think we need
> something like below (uncompiled).

Thanks for looking into this Oleg. I was actually chasing a bug
triggered by trinity where we have a stale cache and vmacache_find() is
returning a bogus vma structure even when vma->vm_mm != mm:

https://lkml.org/lkml/2014/3/9/201
https://lkml.org/lkml/2014/3/11/563

So it just might be a real problem.

--
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/