• David Hildenbrand's avatar
    mm/migrate: convert add_page_for_migration() from follow_page() to folio_walk · 7dff875c
    David Hildenbrand authored
    Let's use folio_walk instead, so we can avoid taking a folio reference
    when we won't even be trying to migrate the folio and to get rid of
    another follow_page()/FOLL_DUMP user.  Use FW_ZEROPAGE so we can return
    "-EFAULT" for it as documented.
    
    We now perform the folio_likely_mapped_shared() check under PTL, which is
    what we want: relying on the mapcount and friends after dropping the PTL
    does not make too much sense, as the page can get unmapped concurrently
    from this process.
    
    Further, we perform the folio isolation under PTL, similar to how we
    handle it for MADV_PAGEOUT.
    
    The possible return values for follow_page() were confusing, especially
    with FOLL_DUMP set. We'll handle it like documented in the man page:
     * -EFAULT: This is a zero page or the memory area is not mapped by the
        process.
     * -ENOENT: The page is not present.
    
    We'll keep setting -ENOENT for ZONE_DEVICE.  Maybe not the right thing to
    do, but it likely doesn't really matter (just like for weird devmap,
    whereby we fake "not present").
    
    The other errros are left as is, and match the documentation in the man
    page.
    
    While at it, rename add_page_for_migration() to add_folio_for_migration().
    
    We'll lose the "secretmem" check, but that shouldn't really matter because
    these folios cannot ever be migrated.  Should vma_migratable() refuse
    these VMAs?  Maybe.
    
    Link: https://lkml.kernel.org/r/20240802155524.517137-5-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.com>
    Cc: Alexander Gordeev <agordeev@linux.ibm.com>
    Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
    Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
    Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
    Cc: Heiko Carstens <hca@linux.ibm.com>
    Cc: Janosch Frank <frankja@linux.ibm.com>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Sven Schnelle <svens@linux.ibm.com>
    Cc: Vasily Gorbik <gor@linux.ibm.com>
    Cc: Ryan Roberts <ryan.roberts@arm.com>
    Cc: Zi Yan <ziy@nvidia.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    7dff875c
migrate.c 71.2 KB