• Zi Yan's avatar
    mm/page_isolation: fix isolate_single_pageblock() isolation behavior · 80e2b584
    Zi Yan authored
    set_migratetype_isolate() does not allow isolating MIGRATE_CMA pageblocks
    unless it is used for CMA allocation.  isolate_single_pageblock() did not
    have the same behavior when it is used together with
    set_migratetype_isolate() in start_isolate_page_range().  This allows
    alloc_contig_range() with migratetype other than MIGRATE_CMA, like
    MIGRATE_MOVABLE (used by alloc_contig_pages()), to isolate first and last
    pageblock but fail the rest.  The failure leads to changing migratetype of
    the first and last pageblock to MIGRATE_MOVABLE from MIGRATE_CMA,
    corrupting the CMA region.  This can happen during gigantic page
    allocations.
    
    Like Doug said here:
    https://lore.kernel.org/linux-mm/a3363a52-883b-dcd1-b77f-f2bb378d6f2d@gmail.com/T/#u,
    for gigantic page allocations, the user would notice no difference,
    since the allocation on CMA region will fail as well as it did before. 
    But it might hurt the performance of device drivers that use CMA, since
    CMA region size decreases.
    
    Fix it by passing migratetype into isolate_single_pageblock(), so that
    set_migratetype_isolate() used by isolate_single_pageblock() will prevent
    the isolation happening.
    
    Link: https://lkml.kernel.org/r/20220914023913.1855924-1-zi.yan@sent.com
    Fixes: b2c9e2fb ("mm: make alloc_contig_range work at pageblock granularity")
    Signed-off-by: default avatarZi Yan <ziy@nvidia.com>
    Reported-by: default avatarDoug Berger <opendmb@gmail.com>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: Doug Berger <opendmb@gmail.com>
    Cc: Mike Kravetz <mike.kravetz@oracle.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    80e2b584
page_isolation.c 20.8 KB