From: Oleg Nesterov <oleg@redhat.com>
To: Davidlohr Bueso <davidlohr@hp.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Michel Lespinasse <walken@google.com>,
Mel Gorman <mgorman@suse.de>, Rik van Riel <riel@redhat.com>,
KOSAKI Motohiro <kosaki.motohiro@gmail.com>,
Davidlohr Bueso <davi@redhat.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH -next] mm,vmacache: also flush cache for VM_CLONE
Date: Thu, 13 Mar 2014 16:32:18 +0100 [thread overview]
Message-ID: <20140313153218.GA28278@redhat.com> (raw)
In-Reply-To: <20140313145941.GA26215@redhat.com>
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).
Oleg.
--- x/mm/vmacache.c
+++ x/mm/vmacache.c
@@ -30,20 +30,24 @@ void vmacache_flush_all(struct mm_struct
rcu_read_unlock();
}
+static bool vmacache_valid_mm(mm)
+{
+ return current->mm == mm && !(current->flags & PF_KTHREAD);
+}
+
void vmacache_update(unsigned long addr, struct vm_area_struct *newvma)
{
- int idx = VMACACHE_HASH(addr);
- current->vmacache[idx] = newvma;
+ if (vmacache_valid_mm(newvma->vm_mm))
+ current->vmacache[VMACACHE_HASH(addr)] = newvma;
}
static bool vmacache_valid(struct mm_struct *mm)
{
- struct task_struct *curr = current;
-
- if (mm != curr->mm)
+ if (!vmacache_valid_mm(mm))
return false;
if (mm->vmacache_seqnum != curr->vmacache_seqnum) {
+ struct task_struct *curr = current;
/*
* First attempt will always be invalid, initialize
* the new cache for this task here.
next prev parent reply other threads:[~2014-03-13 15:33 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-27 21:48 [PATCH v4] mm: per-thread vma caching Davidlohr Bueso
2014-02-28 4:39 ` Davidlohr Bueso
[not found] ` <20140303160021.3001634fa62781d7b0359158@linux-foundation.org>
2014-03-04 0:18 ` Davidlohr Bueso
[not found] ` <20140303164002.02df915e12d05bb98762407f@linux-foundation.org>
2014-03-04 0:59 ` Davidlohr Bueso
[not found] ` <20140303172348.3f00c9df.akpm@linux-foundation.org>
2014-03-04 2:42 ` Davidlohr Bueso
[not found] ` <20140303191224.96f93142.akpm@linux-foundation.org>
2014-03-04 3:13 ` Davidlohr Bueso
2014-03-04 3:26 ` Linus Torvalds
2014-03-04 5:32 ` Davidlohr Bueso
2014-03-14 3:05 ` Li Zefan
2014-03-14 4:43 ` Andrew Morton
2014-03-06 22:56 ` Andrew Morton
[not found] ` <20140308184040.GA29602@redhat.com>
[not found] ` <CA+55aFw88xiY+o5FE6VtHNkpUZDK3FPt31oCpNsgn1BH7wAPZw@mail.gmail.com>
2014-03-08 19:57 ` Oleg Nesterov
[not found] ` <20140308194405.GA32403@redhat.com>
2014-03-08 20:02 ` Linus Torvalds
2014-03-09 3:22 ` Davidlohr Bueso
2014-03-09 12:57 ` Oleg Nesterov
2014-03-09 15:57 ` Linus Torvalds
2014-03-09 17:09 ` Oleg Nesterov
2014-03-09 17:16 ` Linus Torvalds
2014-03-10 19:56 ` [PATCH -next] mm,vmacache: also flush cache for VM_CLONE Davidlohr Bueso
2014-03-13 14:59 ` Oleg Nesterov
2014-03-13 15:32 ` Oleg Nesterov [this message]
2014-03-13 19:04 ` Davidlohr Bueso
[not found] ` <CA+55aFyNd7L+G3hFauJPxUOengK-_o2G-SFmVooPZ-sE6xBj=g@mail.gmail.com>
2014-03-13 16:36 ` Oleg Nesterov
2014-03-13 18:27 ` async_pf.c && use_mm() (Was: mm,vmacache: also flush cache for VM_CLONE) Oleg Nesterov
[not found] ` <CA+55aFwqTbsYCyPf6_i6RmBkPHpEhJjiRfZm6_1_yPa_kUkYiQ@mail.gmail.com>
2014-03-13 21:44 ` Linus Torvalds
2014-03-14 18:23 ` Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140313153218.GA28278@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=davi@redhat.com \
--cc=davidlohr@hp.com \
--cc=kosaki.motohiro@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=riel@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=walken@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox