mm/khugepaged: check compound_order() in collapse_pte_mapped_thp()
Subsystems (2)
PATCH v2 1/1 mm/khugepaged: check compound_order() in collapse_pte_mapped_thp()
By the time we lock a page in collapse_pte_mapped_thp(), the page mapped by the address pushed onto the slot's .pte_mapped_thp[] array might have changed arbitrarily since we last looked at it. We revalidate that the page is still the head of a compound page, but we don't revalidate if the compound page is of order HPAGE_PMD_ORDER before applying rmap and page table updates.
Since the kernel now supports large folios of arbitrary order, and since replacing page's pte mappings by a pmd mapping only makes sense for compound pages of order HPAGE_PMD_ORDER, revalidate that the compound order is indeed of order HPAGE_PMD_ORDER before proceeding.
--- mm/khugepaged.c | 3 +++ 1 file changed, 3 insertions(+)
mm/khugepaged.c +3 -0
@@ -1399,6 +1399,9 @@ void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr)if (!PageHead (hpage)) goto drop_hpage; +if (compound_order (hpage) !=HPAGE_PMD_ORDER ) + goto drop_hpage; +if (find_pmd_or_thp_or_none (mm, haddr, &pmd) !=SCAN_SUCCEED ) goto drop_hpage;
Signature · 1 line
2.37.3.998.g577e59143f-goog
Quoted 8 lines · Zach O'Keefe
By the time we lock a page in
collapse_pte_mapped_thp(), the page mapped by the address pushed onto the slot's .pte_mapped_thp[] array might have changed arbitrarily since we last looked at it. We revalidate that the page is still the head of a compound page, but we don't revalidate if the compound page is of orderHPAGE_PMD_ORDERbefore applying rmap and page table updates.
Quoted 8 lines
Since the kernel now supports large folios of arbitrary order, and since replacing page's pte mappings by a pmd mapping only makes sense for compound pages of order
HPAGE_PMD_ORDER, revalidate that the compound order is indeed of orderHPAGE_PMD_ORDERbefore proceeding.
Quoted 21 lines
--- mm/khugepaged.c | 3 +++ 1 file changed, 3 insertions(+)mm/khugepaged.c +3
-1@@ -1399,6 +1399,9 @@ void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr)if (!PageHead (hpage)) goto drop_hpage; +if (compound_order (hpage) !=HPAGE_PMD_ORDER ) + goto drop_hpage; +if (find_pmd_or_thp_or_none (mm, haddr, &pmd) !=SCAN_SUCCEED ) goto drop_hpage; --2.37.3.998.g577e59143f-goog