Skip to content

Commit c2cb0dc

Browse files
nhoriguchiakpm00
authored andcommitted
mm/hugetlb: separate path for hwpoison entry in copy_hugetlb_page_range()
Originally copy_hugetlb_page_range() handles migration entries and hwpoisoned entries in similar manner. But recently the related code path has more code for migration entries, and when is_writable_migration_entry() was converted to !is_readable_migration_entry(), hwpoison entries on source processes got to be unexpectedly updated (which is legitimate for migration entries, but not for hwpoison entries). This results in unexpected serious issues like kernel panic when forking processes with hwpoison entries in pmd. Separate the if branch into one for hwpoison entries and one for migration entries. Link: https://lkml.kernel.org/r/20220704013312.2415700-3-naoya.horiguchi@linux.dev Fixes: 6c28760 ("mm: remember exclusively mapped anonymous pages with PG_anon_exclusive") Signed-off-by: Naoya Horiguchi <naoya.horiguchi@nec.com> Reviewed-by: Miaohe Lin <linmiaohe@huawei.com> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com> Reviewed-by: Muchun Song <songmuchun@bytedance.com> Cc: <stable@vger.kernel.org> [5.18] Cc: David Hildenbrand <david@redhat.com> Cc: Liu Shixin <liushixin2@huawei.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Yang Shi <shy828301@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent f4f451a commit c2cb0dc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mm/hugetlb.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4788,8 +4788,13 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
47884788
* sharing with another vma.
47894789
*/
47904790
;
4791-
} else if (unlikely(is_hugetlb_entry_migration(entry) ||
4792-
is_hugetlb_entry_hwpoisoned(entry))) {
4791+
} else if (unlikely(is_hugetlb_entry_hwpoisoned(entry))) {
4792+
bool uffd_wp = huge_pte_uffd_wp(entry);
4793+
4794+
if (!userfaultfd_wp(dst_vma) && uffd_wp)
4795+
entry = huge_pte_clear_uffd_wp(entry);
4796+
set_huge_pte_at(dst, addr, dst_pte, entry);
4797+
} else if (unlikely(is_hugetlb_entry_migration(entry))) {
47934798
swp_entry_t swp_entry = pte_to_swp_entry(entry);
47944799
bool uffd_wp = huge_pte_uffd_wp(entry);
47954800

0 commit comments

Comments
 (0)