2008-02-19 18:27:17

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH] hugetlb: ensure we do not reference a surplus page after handing it to buddy


When we free a page via free_huge_page and we detect that we are in
surplus the page will be returned to the buddy. After this we no longer
own the page. However at the end free_huge_page we clear out our mapping
pointer from page private. Even where the page is not a surplus we
free the page to the hugepage pool, drop the pool locks and then clear
page private. In either case the page may have been reallocated. BAD.

Make sure we clear out page private before we free the page.

Signed-off-by: Andy Whitcroft <[email protected]>
---
mm/hugetlb.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index cb1b3a7..89e6286 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -120,6 +120,7 @@ static void free_huge_page(struct page *page)
struct address_space *mapping;

mapping = (struct address_space *) page_private(page);
+ set_page_private(page, 0);
BUG_ON(page_count(page));
INIT_LIST_HEAD(&page->lru);

@@ -134,7 +135,6 @@ static void free_huge_page(struct page *page)
spin_unlock(&hugetlb_lock);
if (mapping)
hugetlb_put_quota(mapping, 1);
- set_page_private(page, 0);
}

/*


2008-02-19 18:35:25

by Adam Litke

[permalink] [raw]
Subject: Re: [PATCH] hugetlb: ensure we do not reference a surplus page after handing it to buddy

Indeed. I'll take credit for this thinko...

On Tue, 2008-02-19 at 18:28 +0000, Andy Whitcroft wrote:
> When we free a page via free_huge_page and we detect that we are in
> surplus the page will be returned to the buddy. After this we no longer
> own the page. However at the end free_huge_page we clear out our mapping
> pointer from page private. Even where the page is not a surplus we
> free the page to the hugepage pool, drop the pool locks and then clear
> page private. In either case the page may have been reallocated. BAD.
>
> Make sure we clear out page private before we free the page.
>
> Signed-off-by: Andy Whitcroft <[email protected]>

Acked-by: Adam Litke <[email protected]>

--
Adam Litke - (agl at us.ibm.com)
IBM Linux Technology Center

2008-02-19 23:37:05

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] hugetlb: ensure we do not reference a surplus page after handing it to buddy

On Tue, 19 Feb 2008 12:41:51 -0600 Adam Litke <[email protected]> wrote:

> Indeed. I'll take credit for this thinko...
>
> On Tue, 2008-02-19 at 18:28 +0000, Andy Whitcroft wrote:
> > When we free a page via free_huge_page and we detect that we are in
> > surplus the page will be returned to the buddy. After this we no longer
> > own the page. However at the end free_huge_page we clear out our mapping
> > pointer from page private. Even where the page is not a surplus we
> > free the page to the hugepage pool, drop the pool locks and then clear
> > page private. In either case the page may have been reallocated. BAD.
> >
> > Make sure we clear out page private before we free the page.
> >
> > Signed-off-by: Andy Whitcroft <[email protected]>
>
> Acked-by: Adam Litke <[email protected]>

Was I right to assume that this is also needed in 2.6.24.x?

2008-02-20 14:52:57

by Adam Litke

[permalink] [raw]
Subject: Re: [PATCH] hugetlb: ensure we do not reference a surplus page after handing it to buddy


On Tue, 2008-02-19 at 15:30 -0800, Andrew Morton wrote:
> On Tue, 19 Feb 2008 12:41:51 -0600 Adam Litke <[email protected]> wrote:
>
> > Indeed. I'll take credit for this thinko...
> >
> > On Tue, 2008-02-19 at 18:28 +0000, Andy Whitcroft wrote:
> > > When we free a page via free_huge_page and we detect that we are in
> > > surplus the page will be returned to the buddy. After this we no longer
> > > own the page. However at the end free_huge_page we clear out our mapping
> > > pointer from page private. Even where the page is not a surplus we
> > > free the page to the hugepage pool, drop the pool locks and then clear
> > > page private. In either case the page may have been reallocated. BAD.
> > >
> > > Make sure we clear out page private before we free the page.
> > >
> > > Signed-off-by: Andy Whitcroft <[email protected]>
> >
> > Acked-by: Adam Litke <[email protected]>
>
> Was I right to assume that this is also needed in 2.6.24.x?

Yep. Thanks Andrew.

--
Adam Litke - (agl at us.ibm.com)
IBM Linux Technology Center