• Axel Rasmussen's avatar
    userfaultfd/selftests: reinitialize test context in each test · 8ba6e864
    Axel Rasmussen authored
    Currently, the context (fds, mmap-ed areas, etc.) are global.  Each test
    mutates this state in some way, in some cases really "clobbering it"
    (e.g., the events test mremap-ing area_dst over the top of area_src, or
    the minor faults tests overwriting the count_verify values in the test
    areas).  We run the tests in a particular order, each test is careful to
    make the right assumptions about its starting state, etc.
    
    But, this is fragile.  It's better for a test's success or failure to not
    depend on what some other prior test case did to the global state.
    
    To that end, clear and reinitialize the test context at the start of each
    test case, so whatever prior test cases did doesn't affect future tests.
    
    This is particularly relevant to this series because the events test's
    mremap of area_dst screws up assumptions the minor fault test was relying
    on.  This wasn't a problem for hugetlb, as we don't mremap in that case.
    
    [peterx@redhat.com: fix conflict between this patch and the uffd pagemap series]
      Link: https://lkml.kernel.org/r/YKQqKrl+/cQ1utrb@t490s
    
    Link: https://lkml.kernel.org/r/20210503180737.2487560-10-axelrasmussen@google.com
    
    Signed-off-by: default avatarAxel Rasmussen <axelrasmussen@google.com>
    Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
    Reviewed-by: default avatarPeter Xu <peterx@redhat.com>
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Cc: Andrea Arcangeli <aarcange@redhat.com>
    Cc: Brian Geffon <bgeffon@google.com>
    Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Jerome Glisse <jglisse@redhat.com>
    Cc: Joe Perches <joe@perches.com>
    Cc: Kirill A. Shutemov <kirill@shutemov.name>
    Cc: Lokesh Gidra <lokeshgidra@google.com>
    Cc: Mike Kravetz <mike.kravetz@oracle.com>
    Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
    Cc: Mina Almasry <almasrymina@google.com>
    Cc: Oliver Upton <oupton@google.com>
    Cc: Shaohua Li <shli@fb.com>
    Cc: Shuah Khan <shuah@kernel.org>
    Cc: Stephen Rothwell <sfr@canb.auug.org.au>
    Cc: Wang Qing <wangqing@vivo.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    8ba6e864
userfaultfd.c 43.8 KB