Skip to content

Commit 73bdf65

Browse files
mjkravetzakpm00
authored andcommitted
migrate: hugetlb: check for hugetlb shared PMD in node migration
migrate_pages/mempolicy semantics state that CAP_SYS_NICE is required to move pages shared with another process to a different node. page_mapcount > 1 is being used to determine if a hugetlb page is shared. However, a hugetlb page will have a mapcount of 1 if mapped by multiple processes via a shared PMD. As a result, hugetlb pages shared by multiple processes and mapped with a shared PMD can be moved by a process without CAP_SYS_NICE. To fix, check for a shared PMD if mapcount is 1. If a shared PMD is found consider the page shared. Link: https://lkml.kernel.org/r/[email protected] Fixes: e2d8cf4 ("migrate: add hugepage migration code to migrate_pages()") Signed-off-by: Mike Kravetz <[email protected]> Acked-by: Peter Xu <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: James Houghton <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Muchun Song <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: Vishal Moola (Oracle) <[email protected]> Cc: Yang Shi <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 3489dbb commit 73bdf65

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mm/mempolicy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,8 @@ static int queue_pages_hugetlb(pte_t *pte, unsigned long hmask,
600600

601601
/* With MPOL_MF_MOVE, we migrate only unshared hugepage. */
602602
if (flags & (MPOL_MF_MOVE_ALL) ||
603-
(flags & MPOL_MF_MOVE && page_mapcount(page) == 1)) {
603+
(flags & MPOL_MF_MOVE && page_mapcount(page) == 1 &&
604+
!hugetlb_pmd_shared(pte))) {
604605
if (isolate_hugetlb(page, qp->pagelist) &&
605606
(flags & MPOL_MF_STRICT))
606607
/*

0 commit comments

Comments
 (0)