• Mike Rapoport's avatar
    mm/gup: continue VM_FAULT_RETRY processing even for pre-faults · df17277b
    Mike Rapoport authored
    When get_user_pages*() is called with pages = NULL, the processing of
    VM_FAULT_RETRY terminates early without actually retrying to fault-in all
    the pages.
    
    If the pages in the requested range belong to a VMA that has userfaultfd
    registered, handle_userfault() returns VM_FAULT_RETRY *after* user space
    has populated the page, but for the gup pre-fault case there's no actual
    retry and the caller will get no pages although they are present.
    
    This issue was uncovered when running post-copy memory restore in CRIU
    after d9c9ce34 ("x86/fpu: Fault-in user stack if
    copy_fpstate_to_sigframe() fails").
    
    After this change, the copying of FPU state to the sigframe switched from
    copy_to_user() variants which caused a real page fault to get_user_pages()
    with pages parameter set to NULL.
    
    In post-copy mode of CRIU, the destination memory is managed with
    userfaultfd and lack of the retry for pre-fault case in get_user_pages()
    causes a crash of the restored ...
    df17277b
gup.c 60.9 KB