mm/khugepaged: check compound_order() in collapse_pte_mapped_thp()
Subsystems (2)
PATCH 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.
---
Andrew, could you please take this into mm-unstable as a prerequisite patch for the "mm: add file/shmem support to MADV_COLLAPSE" series? Thank you.
mm/khugepaged.c | 5 +++++ 1 file changed, 5 insertions(+)
mm/khugepaged.c +5 -0
@@ -1448,6 +1448,11 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, goto drop_hpage; } +if (compound_order (hpage) !=HPAGE_PMD_ORDER ) { + result =SCAN_PAGE_COMPOUND ; + goto drop_hpage; + } + result =find_pmd_or_thp_or_none (mm, haddr, &pmd);switch (result) {case SCAN_SUCCEED :
Signature · 1 line
2.37.3.998.g577e59143f-goog
Quoted 41 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.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.Suggested-by Yang Shi <[email protected]>Signed-off-by Zach O'Keefe <[email protected]>---
Andrew, could you please take this into mm-unstable as a prerequisite patch for the "mm: add file/shmem support to
MADV_COLLAPSE" series? Thank you.mm/khugepaged.c | 5 +++++ 1 file changed, 5 insertions(+)mm/khugepaged.c +5
-1@@ -1448,6 +1448,11 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, goto drop_hpage; } +if (compound_order (hpage) !=HPAGE_PMD_ORDER ) { + result =SCAN_PAGE_COMPOUND ; + goto drop_hpage; + } + result =find_pmd_or_thp_or_none (mm, haddr, &pmd);switch (result) {case SCAN_SUCCEED : --
Quoted 2 lines
2.37.3.998.g577e59143f-goog
Apologies, I forgot the relevant Link tag:
Quoted 48 lines · Zach O'Keefe
Quoted 41 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.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.Suggested-by Yang Shi <[email protected]>Signed-off-by Zach O'Keefe <[email protected]>---
Andrew, could you please take this into mm-unstable as a prerequisite patch for the "mm: add file/shmem support to
MADV_COLLAPSE" series? Thank you.mm/khugepaged.c | 5 +++++ 1 file changed, 5 insertions(+)mm/khugepaged.c +5
-1@@ -1448,6 +1448,11 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, goto drop_hpage; } +if (compound_order (hpage) !=HPAGE_PMD_ORDER ) { + result =SCAN_PAGE_COMPOUND ; + goto drop_hpage; + } + result =find_pmd_or_thp_or_none (mm, haddr, &pmd);switch (result) {case SCAN_SUCCEED : --Quoted 2 lines
2.37.3.998.g577e59143f-goog
Apologies, I forgot the relevant Link tag:
Quoted 1 line
Apologies x2 ; I mentioned this was a prerequisite for the "mm: add file/shmem support to MADV_COLLAPSE" series, but it's based on the current mm-unstable (which includes said series, and thus doesn't even compile). I'll send a v2 of this patch emminitely, along with a v4 of the "mm: add file/shmem support to MADV_COLLAPSE" series - applied in the correct order.