• Peter Xu's avatar
    mm/shmem: handle uffd-wp special pte in page fault handler · 9c28a205
    Peter Xu authored
    File-backed memories are prone to unmap/swap so the ptes are always
    unstable, because they can be easily faulted back later using the page
    cache.  This could lead to uffd-wp getting lost when unmapping or swapping
    out such memory.  One example is shmem.  PTE markers are needed to store
    those information.
    
    This patch prepares it by handling uffd-wp pte markers first it is applied
    elsewhere, so that the page fault handler can recognize uffd-wp pte
    markers.
    
    The handling of uffd-wp pte markers is similar to missing fault, it's just
    that we'll handle this "missing fault" when we see the pte markers,
    meanwhile we need to make sure the marker information is kept during
    processing the fault.
    
    This is a slow path of uffd-wp handling, because zapping of wr-protected
    shmem ptes should be rare.  So far it should only trigger in two
    conditions:
    
      (1) When trying to punch holes in shmem_fallocate(), there is an
          optimization to zap the pgtables before evicting the page.
    
      (2) When swapping out shmem pages.
    
    Because of this, the page fault handling is simplifed too by not sending
    the wr-protect message in the 1st page fault, instead the page will be
    installed read-only, so the uffd-wp message will be generated in the next
    fault, which will trigger the do_wp_page() path of general uffd-wp
    handling.
    
    Disable fault-around for all uffd-wp registered ranges for extra safety
    just like uffd-minor fault, and clean the code up.
    
    Link: https://lkml.kernel.org/r/20220405014844.14239-1-peterx@redhat.comSigned-off-by: default avatarPeter Xu <peterx@redhat.com>
    Cc: Alistair Popple <apopple@nvidia.com>
    Cc: Andrea Arcangeli <aarcange@redhat.com>
    Cc: Axel Rasmussen <axelrasmussen@google.com>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Jerome Glisse <jglisse@redhat.com>
    Cc: "Kirill A . Shutemov" <kirill@shutemov.name>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Mike Kravetz <mike.kravetz@oracle.com>
    Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
    Cc: Nadav Amit <nadav.amit@gmail.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    9c28a205
memory.c 155 KB