• Nadav Amit's avatar
    userfaultfd: change mmap_changing to atomic · a759a909
    Nadav Amit authored
    Patch series "userfaultfd: minor bug fixes".
    
    Three unrelated bug fixes. The first two addresses possible issues (not
    too theoretical ones), but I did not encounter them in practice.
    
    The third patch addresses a test bug that causes the test to fail on my
    system. It has been sent before as part of a bigger RFC.
    
    This patch (of 3):
    
    mmap_changing is currently a boolean variable, which is set and cleared
    without any lock that protects against concurrent modifications.
    
    mmap_changing is supposed to mark whether userfaultfd page-faults handling
    should be retried since mappings are undergoing a change.  However,
    concurrent calls, for instance to madvise(MADV_DONTNEED), might cause
    mmap_changing to be false, although the remove event was still not read
    (hence acknowledged) by the user.
    
    Change mmap_changing to atomic_t and increase/decrease appropriately.  Add
    a debug assertion to see whether mmap_changing is negative.
    
    Link: https://lkml.kernel.org/r/20210808020724.1022515-1-namit@vmware.com
    Link: https://lkml.kernel.org/r/20210808020724.1022515-2-namit@vmware.com
    Fixes: df2cc96e ("userfaultfd: prevent non-cooperative events vs mcopy_atomic races")
    Signed-off-by: default avatarNadav Amit <namit@vmware.com>
    Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
    Cc: Peter Xu <peterx@redhat.com>
    Cc: Axel Rasmussen <axelrasmussen@google.com>
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Cc: Andrea Arcangeli <aarcange@redhat.com>
    Cc: Jens Axboe <axboe@kernel.dk>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    a759a909
userfaultfd.c 54.4 KB