The patch titled Subject: mm/gup: check every subpage of a compound page during isolation has been added to the -mm tree. Its filename is mm-gup-check-every-subpage-of-a-compound-page-during-isolation.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/mm-gup-check-every-subpage-of-a-compound-page-during-isolation.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/mm-gup-check-every-subpage-of-a-compound-page-during-isolation.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Pavel Tatashin <pasha.tatashin@xxxxxxxxxx> Subject: mm/gup: check every subpage of a compound page during isolation When pages are isolated in check_and_migrate_movable_pages() we skip compound number of pages at a time. However, as Jason noted, it is not necessary correct that pages[i] corresponds to the pages that we skipped. This is because it is possible that the addresses in this range had split_huge_pmd()/split_huge_pud(), and these functions do not update the compound page metadata. The problem can be reproduced if something like this occurs: 1. User faulted huge pages. 2. split_huge_pmd() was called for some reason 3. User has unmapped some sub-pages in the range 4. User tries to longterm pin the addresses. The resulting pages[i] might end-up having pages which are not compound size page aligned. Link: https://lkml.kernel.org/r/20210201153827.444374-3-pasha.tatashin@xxxxxxxxxx Fixes: aa712399c1e8 ("mm/gup: speed up check_and_migrate_cma_pages() on huge page") Signed-off-by: Pavel Tatashin <pasha.tatashin@xxxxxxxxxx> Reported-by: Jason Gunthorpe <jgg@xxxxxxxxxx> Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx> Cc: Dan Williams <dan.j.williams@xxxxxxxxx> Cc: David Hildenbrand <david@xxxxxxxxxx> Cc: David Rientjes <rientjes@xxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxxxxx> Cc: Ira Weiny <ira.weiny@xxxxxxxxx> Cc: James Morris <jmorris@xxxxxxxxx> Cc: Jason Gunthorpe <jgg@xxxxxxxx> Cc: John Hubbard <jhubbard@xxxxxxxxxx> Cc: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx> Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx> Cc: Mel Gorman <mgorman@xxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Cc: Mike Kravetz <mike.kravetz@xxxxxxxxxx> Cc: Oscar Salvador <osalvador@xxxxxxx> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx> Cc: Sasha Levin <sashal@xxxxxxxxxx> Cc: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx> Cc: Tyler Hicks <tyhicks@xxxxxxxxxxxxxxxxxxx> Cc: Vlastimil Babka <vbabka@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/gup.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) --- a/mm/gup.c~mm-gup-check-every-subpage-of-a-compound-page-during-isolation +++ a/mm/gup.c @@ -1549,26 +1549,23 @@ static long check_and_migrate_cma_pages( unsigned int gup_flags) { unsigned long i; - unsigned long step; bool drain_allow = true; bool migrate_allow = true; LIST_HEAD(cma_page_list); long ret = nr_pages; + struct page *prev_head, *head; struct migration_target_control mtc = { .nid = NUMA_NO_NODE, .gfp_mask = GFP_USER | __GFP_NOWARN, }; check_again: - for (i = 0; i < nr_pages;) { - - struct page *head = compound_head(pages[i]); - - /* - * gup may start from a tail page. Advance step by the left - * part. - */ - step = compound_nr(head) - (pages[i] - head); + prev_head = NULL; + for (i = 0; i < nr_pages; i++) { + head = compound_head(pages[i]); + if (head == prev_head) + continue; + prev_head = head; /* * If we get a page from the CMA zone, since we are going to * be pinning these entries, we might as well move them out @@ -1592,8 +1589,6 @@ check_again: } } } - - i += step; } if (!list_empty(&cma_page_list)) { _ Patches currently in -mm which might be from pasha.tatashin@xxxxxxxxxx are mm-gup-dont-pin-migrated-cma-pages-in-movable-zone.patch mm-gup-check-every-subpage-of-a-compound-page-during-isolation.patch mm-gup-return-an-error-on-migration-failure.patch mm-gup-check-for-isolation-errors.patch mm-cma-rename-pf_memalloc_nocma-to-pf_memalloc_pin.patch mm-apply-per-task-gfp-constraints-in-fast-path.patch mm-honor-pf_memalloc_pin-for-all-movable-pages.patch mm-gup-do-not-migrate-zero-page.patch mm-gup-migrate-pinned-pages-out-of-movable-zone.patch memory-hotplugrst-add-a-note-about-zone_movable-and-page-pinning.patch mm-gup-change-index-type-to-long-as-it-counts-pages.patch mm-gup-longterm-pin-migration-cleanup.patch selftests-vm-gup_test-fix-test-flag.patch selftests-vm-gup_test-test-faulting-in-kernel-and-verify-pinnable-pages.patch