Skip to content

Commit

Permalink
mm, hugetlb, soft_offline: save compound page order before page migra…
Browse files Browse the repository at this point in the history
…tion

This fixes a bug in madvise() where if you'd try to soft offline a
hugepage via madvise(), while walking the address range you'd end up,
using the wrong page offset due to attempting to get the compound order
of a former but presently not compound page, due to dissolving the huge
page (since commit c3114a8: "mm: hugetlb: soft-offline: dissolve
source hugepage after successful migration").

As a result I ended up with all my free pages except one being offlined.

Link: http://lkml.kernel.org/r/[email protected]
Fixes: c3114a8 ("mm: hugetlb: soft-offline: dissolve source hugepage after successful migration")
Signed-off-by: Alexandru Moise <[email protected]>
Cc: Anshuman Khandual <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Hillf Danton <[email protected]>
Cc: Shaohua Li <[email protected]>
Cc: Mike Rapoport <[email protected]>
Cc: "Kirill A. Shutemov" <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Naoya Horiguchi <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
MosesAlexander authored and torvalds committed Oct 4, 2017
1 parent 4b22927 commit 19bfbe2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mm/madvise.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,18 +625,26 @@ static int madvise_inject_error(int behavior,
{
struct page *page;
struct zone *zone;
unsigned int order;

if (!capable(CAP_SYS_ADMIN))
return -EPERM;

for (; start < end; start += PAGE_SIZE <<
compound_order(compound_head(page))) {

for (; start < end; start += PAGE_SIZE << order) {
int ret;

ret = get_user_pages_fast(start, 1, 0, &page);
if (ret != 1)
return ret;

/*
* When soft offlining hugepages, after migrating the page
* we dissolve it, therefore in the second loop "page" will
* no longer be a compound page, and order will be 0.
*/
order = compound_order(compound_head(page));

if (PageHWPoison(page)) {
put_page(page);
continue;
Expand Down

0 comments on commit 19bfbe2

Please sign in to comment.