• Lorenzo Stoakes's avatar
    mm: remove duplicated open-coded VMA policy check · 3e01310d
    Lorenzo Stoakes authored
    Both can_vma_merge_before() and can_vma_merge_after() are invoked after
    checking for compatible VMA NUMA policy, we can simply move this to
    is_mergeable_vma() and abstract this altogether.
    
    In mmap_region() we set vmg->policy to NULL, so the policy comparisons
    checked in can_vma_merge_before() and can_vma_merge_after() are exactly
    equivalent to !vma_policy(vmg.next) and !vma_policy(vmg.prev).
    
    Equally, in do_brk_flags(), vmg->policy is NULL, so the
    can_vma_merge_after() is checking !vma_policy(vma), as we set vmg.prev to
    vma.
    
    In vma_merge(), we compare prev and next policies with vmg->policy before
    checking can_vma_merge_after() and can_vma_merge_before() respectively,
    which this patch causes to be checked in precisely the same way.
    
    This therefore maintains precisely the same logic as before, only now
    abstracted into is_mergeable_vma().
    
    Link: https://lkml.kernel.org/r/0dbff286d9c4988333bc6f4ff3734cb95dd5410a.1725040657.git.lorenzo.stoakes@oracle.comSigned-off-by: default avatarLorenzo Stoakes <lorenzo.stoakes@oracle.com>
    Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
    Reviewed-by: default avatarLiam R. Howlett <Liam.Howlett@oracle.com>
    Cc: Mark Brown <broonie@kernel.org>
    Cc: Bert Karwatzki <spasswolf@web.de>
    Cc: Jeff Xu <jeffxu@chromium.org>
    Cc: Jiri Olsa <olsajiri@gmail.com>
    Cc: Kees Cook <kees@kernel.org>
    Cc: Lorenzo Stoakes <lstoakes@gmail.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: "Paul E. McKenney" <paulmck@kernel.org>
    Cc: Paul Moore <paul@paul-moore.com>
    Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
    Cc: Suren Baghdasaryan <surenb@google.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    3e01310d
vma.c 51.4 KB