• Liam Howlett's avatar
    maple_tree: be more cautious about dead nodes · 39d0bd86
    Liam Howlett authored
    Patch series "Fix VMA tree modification under mmap read lock".
    
    Syzbot reported a BUG_ON in mm/mmap.c which was found to be caused by an
    inconsistency between threads walking the VMA maple tree.  The
    inconsistency is caused by the page fault handler modifying the maple tree
    while holding the mmap_lock for read.
    
    This only happens for stack VMAs.  We had thought this was safe as it only
    modifies a single pivot in the tree.  Unfortunately, syzbot constructed a
    test case where the stack had no guard page and grew the stack to abut the
    next VMA.  This causes us to delete the NULL entry between the two VMAs
    and rewrite the node.
    
    We considered several options for fixing this, including dropping the
    mmap_lock, then reacquiring it for write; and relaxing the definition of
    the tree to permit a zero-length NULL entry in the node.  We decided the
    best option was to backport some of the RCU patches from -next, which
    solve the problem by allocating a new node and RCU-freeing the old node. 
    Since the problem exists in 6.1, we preferred a solution which is similar
    to the one we intended to merge next merge window.
    
    These patches have been in -next since next-20230301, and have received
    intensive testing in Android as part of the RCU page fault patchset.  They
    were also sent as part of the "Per-VMA locks" v4 patch series.  Patches 1
    to 7 are bug fixes for RCU mode of the tree and patch 8 enables RCU mode
    for the tree.
    
    Performance v6.3-rc3 vs patched v6.3-rc3: Running these changes through
    mmtests showed there was a 15-20% performance decrease in
    will-it-scale/brk1-processes.  This tests creating and inserting a single
    VMA repeatedly through the brk interface and isn't representative of any
    real world applications.
    
    
    This patch (of 8):
    
    ma_pivots() and ma_data_end() may be called with a dead node.  Ensure to
    that the node isn't dead before using the returned values.
    
    This is necessary for RCU mode of the maple tree.
    
    Link: https://lkml.kernel.org/r/20230327185532.2354250-1-Liam.Howlett@oracle.com
    Link: https://lkml.kernel.org/r/20230227173632.3292573-1-surenb@google.com
    Link: https://lkml.kernel.org/r/20230227173632.3292573-2-surenb@google.com
    Fixes: 54a611b6 ("Maple Tree: add new data structure")
    Signed-off-by: default avatarLiam Howlett <Liam.Howlett@oracle.com>
    Signed-off-by: default avatarSuren Baghdasaryan <surenb@google.com>
    Cc: Andy Lutomirski <luto@kernel.org>
    Cc: Arjun Roy <arjunroy@google.com>
    Cc: Axel Rasmussen <axelrasmussen@google.com>
    Cc: Chris Li <chriscli@google.com>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: David Howells <dhowells@redhat.com>
    Cc: Davidlohr Bueso <dave@stgolabs.net>
    Cc: David Rientjes <rientjes@google.com>
    Cc: Eric Dumazet <edumazet@google.com>
    Cc: freak07 <michalechner92@googlemail.com>
    Cc: Greg Thelen <gthelen@google.com>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jann Horn <jannh@google.com>
    Cc: Joel Fernandes <joelaf@google.com>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Kent Overstreet <kent.overstreet@linux.dev>
    Cc: Laurent Dufour <ldufour@linux.ibm.com>
    Cc: Lorenzo Stoakes <lstoakes@gmail.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Mel Gorman <mgorman@techsingularity.net>
    Cc: Michal Hocko <mhocko@suse.com>
    Cc: Mike Rapoport <rppt@kernel.org>
    Cc: Minchan Kim <minchan@google.com>
    Cc: Paul E. McKenney <paulmck@kernel.org>
    Cc: Peter Oskolkov <posk@google.com>
    Cc: Peter Xu <peterx@redhat.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Punit Agrawal <punit.agrawal@bytedance.com>
    Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Cc: Shakeel Butt <shakeelb@google.com>
    Cc: Soheil Hassas Yeganeh <soheil@google.com>
    Cc: Song Liu <songliubraving@fb.com>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Cc: Will Deacon <will@kernel.org>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    39d0bd86
maple_tree.c 178 KB