• Liam R. Howlett's avatar
    mm/mmap: clean up validate_mm() calls · 2574d5e4
    Liam R. Howlett authored
    Patch series "More strict maple tree lockdep", v2.
    
    Linus asked for more strict maple tree lockdep checking [1] and for them
    to resume the normal path through Andrews tree.
    
    This series of patches adds checks to ensure the lock is held in write
    mode during the write path of the maple tree instead of checking if it's
    held at all.
    
    It also reduces the validate_mm() calls by consolidating into commonly
    used functions (patch 0001), and removes the necessity of holding the lock
    on the detached tree during munmap() operations.
    
    
    This patch (of 4):
    
    validate_mm() calls are too spread out and duplicated in numerous
    locations.  Also, now that the stack write is done under the write lock,
    it is not necessary to validate the mm prior to write operations.
    
    Add a validate_mm() to the stack expansions, and to vma_complete() so
    that numerous others may be dropped.
    
    Note that vma_link() (and also insert_vm_struct() by call path) already
    call validate_mm().
    
    vma_merge() also had an unnecessary call to vma_iter_free() since the
    logic change to abort earlier if no merging is necessary.
    
    Drop extra validate_mm() calls at the start of functions and error paths
    which won't write to the tree.
    
    Relocate the validate_mm() call in the do_brk_flags() to avoid
    re-running the same test when vma_complete() is used.
    
    The call within the error path of mmap_region() is left intentionally
    because of the complexity of the function and the potential of drivers
    modifying the tree.
    
    Link: https://lkml.kernel.org/r/20230714195551.894800-1-Liam.Howlett@oracle.com
    Link: https://lkml.kernel.org/r/20230714195551.894800-2-Liam.Howlett@oracle.comSigned-off-by: default avatarLiam R. Howlett <Liam.Howlett@oracle.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Oliver Sang <oliver.sang@intel.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    2574d5e4
mmap.c 103 KB