Message ID | 20220922222731.1124481-1-zokeefe@google.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [v2] mm/khugepaged: check compound_order() in collapse_pte_mapped_thp() | expand |
On Thu, Sep 22, 2022 at 3:27 PM Zach O'Keefe <zokeefe@google.com> wrote: > > 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. > > Link: https://lore.kernel.org/linux-mm/CAHbLzkon+2ky8v9ywGcsTUgXM_B35jt5NThYqQKXW2YV_GUacw@mail.gmail.com/ > Suggested-by: Yang Shi <shy828301@gmail.com> > Signed-off-by: Zach O'Keefe <zokeefe@google.com> Reviewed-by: Yang Shi <shy828301@gmail.com> > --- > mm/khugepaged.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 57af2c841b41..40fd9f7b3ed3 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -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 >
> Reviewed-by: Yang Shi <shy828301@gmail.com>
Thanks for taking the time, Yang!
Best,
Zach
diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 57af2c841b41..40fd9f7b3ed3 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -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;
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. Link: https://lore.kernel.org/linux-mm/CAHbLzkon+2ky8v9ywGcsTUgXM_B35jt5NThYqQKXW2YV_GUacw@mail.gmail.com/ Suggested-by: Yang Shi <shy828301@gmail.com> Signed-off-by: Zach O'Keefe <zokeefe@google.com> --- mm/khugepaged.c | 3 +++ 1 file changed, 3 insertions(+)