From: Linus Torvalds <torvalds@linux-foundation.org>
To: "Robert Święcki" <robert@swiecki.net>
Cc: Hugh Dickins <hughd@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Miklos Szeredi <miklos@szeredi.hu>,
Michel Lespinasse <walken@google.com>,
"Eric W. Biederman" <ebiederm@xmission.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Rik van Riel <riel@redhat.com>
Subject: Re: [PATCH] mm: fix possible cause of a page_mapped BUG
Date: Tue, 12 Apr 2011 11:59:18 -0700 [thread overview]
Message-ID: <BANLkTiktvcBWsLKEk5iBYVEbPJS3i+U+hA@mail.gmail.com> (raw)
In-Reply-To: <BANLkTim6ATGxTiMcfK5-03azgcWuT4wtJA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 437 bytes --]
On Tue, Apr 12, 2011 at 10:19 AM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> THIS IS A HACKY AND UNTESTED PATCH!
.. and here is a rather less hacky, but still equally untested patch.
It moves the stack guard page handling into __get_user_pages() itself,
and thus avoids the whole problem.
This one I could easily see myself committing. Assuming I get some
ack's and testing..
Comments?
Linus
[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 3078 bytes --]
mm/memory.c | 26 ++++++++++++++++++--------
mm/mlock.c | 13 -------------
2 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index 9da8cab1b1b0..b623a249918c 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1410,6 +1410,13 @@ no_page_table:
return page;
}
+static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
+{
+ return (vma->vm_flags & VM_GROWSDOWN) &&
+ (vma->vm_start == addr) &&
+ !vma_stack_continue(vma->vm_prev, addr);
+}
+
/**
* __get_user_pages() - pin user pages in memory
* @tsk: task_struct of target task
@@ -1488,7 +1495,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
vma = find_extend_vma(mm, start);
if (!vma && in_gate_area(mm, start)) {
unsigned long pg = start & PAGE_MASK;
- struct vm_area_struct *gate_vma = get_gate_vma(mm);
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd;
@@ -1513,10 +1519,11 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
pte_unmap(pte);
return i ? : -EFAULT;
}
+ vma = get_gate_vma(mm);
if (pages) {
struct page *page;
- page = vm_normal_page(gate_vma, start, *pte);
+ page = vm_normal_page(vma, start, *pte);
if (!page) {
if (!(gup_flags & FOLL_DUMP) &&
is_zero_pfn(pte_pfn(*pte)))
@@ -1530,12 +1537,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
get_page(page);
}
pte_unmap(pte);
- if (vmas)
- vmas[i] = gate_vma;
- i++;
- start += PAGE_SIZE;
- nr_pages--;
- continue;
+ goto next_page;
}
if (!vma ||
@@ -1549,6 +1551,13 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
continue;
}
+ /*
+ * If we don't actually want the page itself,
+ * and it's the stack guard page, just skip it.
+ */
+ if (!pages && stack_guard_page(vma, start))
+ goto next_page;
+
do {
struct page *page;
unsigned int foll_flags = gup_flags;
@@ -1631,6 +1640,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
flush_anon_page(vma, page, start);
flush_dcache_page(page);
}
+next_page:
if (vmas)
vmas[i] = vma;
i++;
diff --git a/mm/mlock.c b/mm/mlock.c
index 2689a08c79af..6b55e3efe0df 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -135,13 +135,6 @@ void munlock_vma_page(struct page *page)
}
}
-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
-{
- return (vma->vm_flags & VM_GROWSDOWN) &&
- (vma->vm_start == addr) &&
- !vma_stack_continue(vma->vm_prev, addr);
-}
-
/**
* __mlock_vma_pages_range() - mlock a range of pages in the vma.
* @vma: target vma
@@ -188,12 +181,6 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
if (vma->vm_flags & VM_LOCKED)
gup_flags |= FOLL_MLOCK;
- /* We don't try to access the guard page of a stack vma */
- if (stack_guard_page(vma, start)) {
- addr += PAGE_SIZE;
- nr_pages--;
- }
-
return __get_user_pages(current, mm, addr, nr_pages, gup_flags,
NULL, NULL, nonblocking);
}
next prev parent reply other threads:[~2011-04-12 19:00 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-24 5:39 [PATCH] mm: fix possible cause of a page_mapped BUG Hugh Dickins
2011-02-28 23:35 ` Robert Święcki
2011-03-17 15:40 ` Robert Święcki
2011-03-19 5:34 ` Hugh Dickins
2011-04-01 14:34 ` Robert Święcki
2011-04-01 15:44 ` Linus Torvalds
2011-04-01 16:21 ` Robert Święcki
2011-04-01 16:35 ` Linus Torvalds
2011-04-02 4:01 ` Hui Zhu
2011-04-04 13:02 ` Robert Święcki
2011-04-02 1:46 ` Hugh Dickins
2011-04-04 12:46 ` Robert Święcki
2011-04-04 18:30 ` Hugh Dickins
2011-04-05 12:21 ` Robert Święcki
2011-04-05 15:37 ` Linus Torvalds
2011-04-06 14:47 ` Hugh Dickins
2011-04-06 15:32 ` Linus Torvalds
2011-04-06 15:43 ` Hugh Dickins
2011-04-06 15:59 ` Linus Torvalds
2011-04-06 17:54 ` Robert Święcki
2011-04-07 12:41 ` Robert Święcki
2011-04-07 14:24 ` Hugh Dickins
2011-04-12 9:58 ` Robert Święcki
2011-04-12 14:21 ` Linus Torvalds
[not found] ` <BANLkTik6U21r91DYiUsz9A0P--=5QcsBrA@mail.gmail.com>
2011-04-12 16:17 ` Robert Święcki
2011-04-12 17:19 ` Linus Torvalds
2011-04-12 18:59 ` Linus Torvalds [this message]
2011-04-12 19:02 ` Robert Święcki
2011-04-12 19:38 ` Linus Torvalds
2011-04-18 21:15 ` Michel Lespinasse
2011-05-05 0:09 ` Michel Lespinasse
2011-05-05 0:38 ` Linus Torvalds
2011-05-05 1:18 ` Michel Lespinasse
2011-05-05 1:40 ` Linus Torvalds
2011-05-05 3:37 ` Linus Torvalds
2011-05-05 4:26 ` Michel Lespinasse
2011-04-07 14:17 ` Hugh Dickins
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=BANLkTiktvcBWsLKEk5iBYVEbPJS3i+U+hA@mail.gmail.com \
--to=torvalds@linux-foundation.org \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=ebiederm@xmission.com \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=miklos@szeredi.hu \
--cc=riel@redhat.com \
--cc=robert@swiecki.net \
--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;
as well as URLs for NNTP newsgroup(s).