From e475977684b4a11fef3dd2e34045f61442570cc8 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 14 Feb 2023 09:56:39 +0100 Subject: [PATCH] 4.14-stable patches added patches: migrate-hugetlb-check-for-hugetlb-shared-pmd-in-node-migration.patch --- ...hugetlb-shared-pmd-in-node-migration.patch | 50 +++++++++++++++++++ queue-4.14/series | 1 + 2 files changed, 51 insertions(+) create mode 100644 queue-4.14/migrate-hugetlb-check-for-hugetlb-shared-pmd-in-node-migration.patch diff --git a/queue-4.14/migrate-hugetlb-check-for-hugetlb-shared-pmd-in-node-migration.patch b/queue-4.14/migrate-hugetlb-check-for-hugetlb-shared-pmd-in-node-migration.patch new file mode 100644 index 00000000000..60511b4f824 --- /dev/null +++ b/queue-4.14/migrate-hugetlb-check-for-hugetlb-shared-pmd-in-node-migration.patch @@ -0,0 +1,50 @@ +From 73bdf65ea74857d7fb2ec3067a3cec0e261b1462 Mon Sep 17 00:00:00 2001 +From: Mike Kravetz +Date: Thu, 26 Jan 2023 14:27:21 -0800 +Subject: migrate: hugetlb: check for hugetlb shared PMD in node migration + +From: Mike Kravetz + +commit 73bdf65ea74857d7fb2ec3067a3cec0e261b1462 upstream. + +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/20230126222721.222195-3-mike.kravetz@oracle.com +Fixes: e2d8cf405525 ("migrate: add hugepage migration code to migrate_pages()") +Signed-off-by: Mike Kravetz +Acked-by: Peter Xu +Acked-by: David Hildenbrand +Cc: James Houghton +Cc: Matthew Wilcox +Cc: Michal Hocko +Cc: Muchun Song +Cc: Naoya Horiguchi +Cc: Vishal Moola (Oracle) +Cc: Yang Shi +Cc: +Signed-off-by: Andrew Morton +Signed-off-by: Greg Kroah-Hartman +--- + mm/mempolicy.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +--- a/mm/mempolicy.c ++++ b/mm/mempolicy.c +@@ -574,7 +574,8 @@ static int queue_pages_hugetlb(pte_t *pt + goto unlock; + /* With MPOL_MF_MOVE, we migrate only unshared hugepage. */ + if (flags & (MPOL_MF_MOVE_ALL) || +- (flags & MPOL_MF_MOVE && page_mapcount(page) == 1)) ++ (flags & MPOL_MF_MOVE && page_mapcount(page) == 1 && ++ !hugetlb_pmd_shared(pte))) + isolate_huge_page(page, qp->pagelist); + unlock: + spin_unlock(ptl); diff --git a/queue-4.14/series b/queue-4.14/series index 3460f36130e..27f4e84fa14 100644 --- a/queue-4.14/series +++ b/queue-4.14/series @@ -30,3 +30,4 @@ pinctrl-aspeed-fix-confusing-types-in-return-value.patch pinctrl-single-fix-potential-null-dereference.patch net-usb-fix-wrong-direction-warning-in-plusb.c.patch usb-core-add-quirk-for-alcor-link-ak9563-smartcard-reader.patch +migrate-hugetlb-check-for-hugetlb-shared-pmd-in-node-migration.patch -- 2.47.2