* [patch] ksm: check for ERR_PTR from follow_page()
@ 2010-04-21 10:27 Dan Carpenter
2010-04-21 15:24 ` Rik van Riel
2010-04-21 23:51 ` Izik Eidus
0 siblings, 2 replies; 7+ messages in thread
From: Dan Carpenter @ 2010-04-21 10:27 UTC (permalink / raw)
To: Izik Eidus
Cc: Hugh Dickins, Andrea Arcangeli, Rik van Riel, linux-kernel,
linux-mm, kernel-janitors, Andrew Morton
The follow_page() function can potentially return -EFAULT so I added
checks for this.
Also I silenced an uninitialized variable warning on my version of gcc
(version 4.3.2).
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
I'm not very familiar with this code, so handle with care.
diff --git a/mm/ksm.c b/mm/ksm.c
index 8cdfc2a..956880f 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -365,7 +365,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
do {
cond_resched();
page = follow_page(vma, addr, FOLL_GET);
- if (!page)
+ if (IS_ERR_OR_NULL(page))
break;
if (PageKsm(page))
ret = handle_mm_fault(vma->vm_mm, vma, addr,
@@ -447,7 +447,7 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
goto out;
page = follow_page(vma, addr, FOLL_GET);
- if (!page)
+ if (IS_ERR_OR_NULL(page))
goto out;
if (PageAnon(page)) {
flush_anon_page(vma, page, addr);
@@ -1086,7 +1086,7 @@ struct rmap_item *unstable_tree_search_insert(struct rmap_item *rmap_item,
cond_resched();
tree_rmap_item = rb_entry(*new, struct rmap_item, node);
tree_page = get_mergeable_page(tree_rmap_item);
- if (!tree_page)
+ if (IS_ERR_OR_NULL(tree_page))
return NULL;
/*
@@ -1294,7 +1294,7 @@ next_mm:
if (ksm_test_exit(mm))
break;
*page = follow_page(vma, ksm_scan.address, FOLL_GET);
- if (*page && PageAnon(*page)) {
+ if (!IS_ERR_OR_NULL(*page) && PageAnon(*page)) {
flush_anon_page(vma, *page, ksm_scan.address);
flush_dcache_page(*page);
rmap_item = get_next_rmap_item(slot,
@@ -1308,7 +1308,7 @@ next_mm:
up_read(&mm->mmap_sem);
return rmap_item;
}
- if (*page)
+ if (!IS_ERR_OR_NULL(*page))
put_page(*page);
ksm_scan.address += PAGE_SIZE;
cond_resched();
@@ -1367,7 +1367,7 @@ next_mm:
static void ksm_do_scan(unsigned int scan_npages)
{
struct rmap_item *rmap_item;
- struct page *page;
+ struct page *uninitialized_var(page);
while (scan_npages--) {
cond_resched();
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [patch] ksm: check for ERR_PTR from follow_page()
2010-04-21 10:27 [patch] ksm: check for ERR_PTR from follow_page() Dan Carpenter
@ 2010-04-21 15:24 ` Rik van Riel
2010-04-21 17:46 ` Andrea Arcangeli
2010-04-21 23:51 ` Izik Eidus
1 sibling, 1 reply; 7+ messages in thread
From: Rik van Riel @ 2010-04-21 15:24 UTC (permalink / raw)
To: Dan Carpenter, Izik Eidus, Hugh Dickins, Andrea Arcangeli,
linux-kernel, linux-mm, kernel-janitors, Andrew Morton
On 04/21/2010 06:27 AM, Dan Carpenter wrote:
> The follow_page() function can potentially return -EFAULT so I added
> checks for this.
>
> Also I silenced an uninitialized variable warning on my version of gcc
> (version 4.3.2).
>
> Signed-off-by: Dan Carpenter<error27@gmail.com>
Acked-by: Rik van Riel <riel@redhat.com>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] ksm: check for ERR_PTR from follow_page()
2010-04-21 15:24 ` Rik van Riel
@ 2010-04-21 17:46 ` Andrea Arcangeli
2010-04-21 20:53 ` Johannes Weiner
0 siblings, 1 reply; 7+ messages in thread
From: Andrea Arcangeli @ 2010-04-21 17:46 UTC (permalink / raw)
To: Rik van Riel
Cc: Dan Carpenter, Izik Eidus, Hugh Dickins, linux-kernel, linux-mm,
kernel-janitors, Andrew Morton
On Wed, Apr 21, 2010 at 11:24:24AM -0400, Rik van Riel wrote:
> On 04/21/2010 06:27 AM, Dan Carpenter wrote:
> > The follow_page() function can potentially return -EFAULT so I added
> > checks for this.
> >
> > Also I silenced an uninitialized variable warning on my version of gcc
> > (version 4.3.2).
> >
> > Signed-off-by: Dan Carpenter<error27@gmail.com>
>
> Acked-by: Rik van Riel <riel@redhat.com>
while (!(page = follow_page(vma, start, foll_flags)))
{
gup only checks for null, so when exactly is follow_page going to
return -EFAULT? It's not immediately clear.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] ksm: check for ERR_PTR from follow_page()
2010-04-21 17:46 ` Andrea Arcangeli
@ 2010-04-21 20:53 ` Johannes Weiner
2010-04-21 20:58 ` Andrea Arcangeli
0 siblings, 1 reply; 7+ messages in thread
From: Johannes Weiner @ 2010-04-21 20:53 UTC (permalink / raw)
To: Andrea Arcangeli
Cc: Rik van Riel, Dan Carpenter, Izik Eidus, Hugh Dickins,
linux-kernel, linux-mm, kernel-janitors, Andrew Morton
On Wed, Apr 21, 2010 at 07:46:15PM +0200, Andrea Arcangeli wrote:
> On Wed, Apr 21, 2010 at 11:24:24AM -0400, Rik van Riel wrote:
> > On 04/21/2010 06:27 AM, Dan Carpenter wrote:
> > > The follow_page() function can potentially return -EFAULT so I added
> > > checks for this.
> > >
> > > Also I silenced an uninitialized variable warning on my version of gcc
> > > (version 4.3.2).
> > >
> > > Signed-off-by: Dan Carpenter<error27@gmail.com>
> >
> > Acked-by: Rik van Riel <riel@redhat.com>
>
> while (!(page = follow_page(vma, start, foll_flags)))
> {
>
> gup only checks for null, so when exactly is follow_page going to
> return -EFAULT? It's not immediately clear.
Check below that loop. If it returns non-null, the first check is
whether it IS_ERR().
How about the below?
Hannes
---
From: Johannes Weiner <hannes@cmpxchg.org>
Subject: mm: document follow_page()
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
mm/memory.c | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index 833952d..119b7cc 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1227,8 +1227,17 @@ int zap_vma_ptes(struct vm_area_struct *vma, unsigned long address,
}
EXPORT_SYMBOL_GPL(zap_vma_ptes);
-/*
- * Do a quick page-table lookup for a single page.
+/**
+ * follow_page - look up a page descriptor from a user-virtual address
+ * @vma: vm_area_struct mapping @address
+ * @address: virtual address to look up
+ * @flags: flags modifying lookup behaviour
+ *
+ * @flags can have FOLL_ flags set, defined in <linux/mm.h>
+ *
+ * Returns the mapped (struct page *), %NULL if no mapping exists, or
+ * an error pointer if there is a mapping to something not represented
+ * by a page descriptor (see also vm_normal_page()).
*/
struct page *follow_page(struct vm_area_struct *vma, unsigned long address,
unsigned int flags)
--
1.7.0.2
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [patch] ksm: check for ERR_PTR from follow_page()
2010-04-21 20:53 ` Johannes Weiner
@ 2010-04-21 20:58 ` Andrea Arcangeli
2010-04-21 21:10 ` Johannes Weiner
0 siblings, 1 reply; 7+ messages in thread
From: Andrea Arcangeli @ 2010-04-21 20:58 UTC (permalink / raw)
To: Johannes Weiner
Cc: Rik van Riel, Dan Carpenter, Izik Eidus, Hugh Dickins,
linux-kernel, linux-mm, kernel-janitors, Andrew Morton
On Wed, Apr 21, 2010 at 10:53:05PM +0200, Johannes Weiner wrote:
> Check below that loop. If it returns non-null, the first check is
> whether it IS_ERR().
Indeed.
> + * Returns the mapped (struct page *), %NULL if no mapping exists, or
> + * an error pointer if there is a mapping to something not represented
> + * by a page descriptor (see also vm_normal_page()).
where exactly in vm_normal_page? Note I already checked vm_normal_page
before sending the prev email and I didn't immediately see. I search
return and they all return NULL except the return pfn_to_page(pfn), so
is pfn_to_page that returns -EFAULT (the implementations I checked
don't but there are plenty that I didn't check...).
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] ksm: check for ERR_PTR from follow_page()
2010-04-21 20:58 ` Andrea Arcangeli
@ 2010-04-21 21:10 ` Johannes Weiner
0 siblings, 0 replies; 7+ messages in thread
From: Johannes Weiner @ 2010-04-21 21:10 UTC (permalink / raw)
To: Andrea Arcangeli
Cc: Rik van Riel, Dan Carpenter, Izik Eidus, Hugh Dickins,
linux-kernel, linux-mm, kernel-janitors, Andrew Morton
On Wed, Apr 21, 2010 at 10:58:07PM +0200, Andrea Arcangeli wrote:
> On Wed, Apr 21, 2010 at 10:53:05PM +0200, Johannes Weiner wrote:
> > + * Returns the mapped (struct page *), %NULL if no mapping exists, or
> > + * an error pointer if there is a mapping to something not represented
> > + * by a page descriptor (see also vm_normal_page()).
>
> where exactly in vm_normal_page? Note I already checked vm_normal_page
> before sending the prev email and I didn't immediately see. I search
> return and they all return NULL except the return pfn_to_page(pfn), so
> is pfn_to_page that returns -EFAULT (the implementations I checked
> don't but there are plenty that I didn't check...).
It's not vm_normal_page() that returns -EFAULT. It is follow_page()
that translates NULL from vm_normal_page() into -EFAULT.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] ksm: check for ERR_PTR from follow_page()
2010-04-21 10:27 [patch] ksm: check for ERR_PTR from follow_page() Dan Carpenter
2010-04-21 15:24 ` Rik van Riel
@ 2010-04-21 23:51 ` Izik Eidus
1 sibling, 0 replies; 7+ messages in thread
From: Izik Eidus @ 2010-04-21 23:51 UTC (permalink / raw)
To: Dan Carpenter
Cc: Hugh Dickins, Andrea Arcangeli, Rik van Riel, linux-kernel,
linux-mm, kernel-janitors, Andrew Morton
On Wed, 21 Apr 2010 12:27:59 +0200
Dan Carpenter <error27@gmail.com> wrote:
Hello
> The follow_page() function can potentially return -EFAULT so I added
> checks for this.
>
> Also I silenced an uninitialized variable warning on my version of gcc
> (version 4.3.2).
>
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---
> I'm not very familiar with this code, so handle with care.
Acked-by: Izik Eidus <ieidus@redhat.com>
Thanks.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-04-21 23:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-21 10:27 [patch] ksm: check for ERR_PTR from follow_page() Dan Carpenter
2010-04-21 15:24 ` Rik van Riel
2010-04-21 17:46 ` Andrea Arcangeli
2010-04-21 20:53 ` Johannes Weiner
2010-04-21 20:58 ` Andrea Arcangeli
2010-04-21 21:10 ` Johannes Weiner
2010-04-21 23:51 ` Izik Eidus
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).