Skip to content

Commit

Permalink
mm/migration: fix possible do_pages_stat_array racing with memory off…
Browse files Browse the repository at this point in the history
…line

When follow_page peeks a page, the page could be migrated and then be
offlined while it's still being used by the do_pages_stat_array().  Use
FOLL_GET to hold the page refcnt to fix this potential race.

Link: https://lkml.kernel.org/r/20220318111709.60311-12-linmiaohe@huawei.com
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Acked-by: "Huang, Ying" <ying.huang@intel.com>
Reviewed-by: Muchun Song <songmuchun@bytedance.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
Miaohe Lin authored and akpm committed Apr 29, 2022
1 parent 3f26c88 commit 4cd6148
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mm/migrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1796,13 +1796,18 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
goto set_status;

/* FOLL_DUMP to ignore special (like zero) pages */
page = follow_page(vma, addr, FOLL_DUMP);
page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);

err = PTR_ERR(page);
if (IS_ERR(page))
goto set_status;

err = page ? page_to_nid(page) : -ENOENT;
if (page) {
err = page_to_nid(page);
put_page(page);
} else {
err = -ENOENT;
}
set_status:
*status = err;

Expand Down

0 comments on commit 4cd6148

Please sign in to comment.