Re: [PATCH] Add mmap_assert_locked() annotations to find_vma*()

From: Andrew Morton
Date: Sun Aug 01 2021 - 15:33:44 EST


On Sat, 31 Jul 2021 10:53:41 -0700 Luigi Rizzo <lrizzo@xxxxxxxxxx> wrote:

> find_vma() and variants need protection when used.
> This patch adds mmap_assert_lock() calls in the functions.
>
> To make sure the invariant is satisfied, we also need to add a
> mmap_read_loc() around the get_user_pages_remote() call in
> get_arg_page(). The lock is not strictly necessary because the mm
> has been newly created, but the extra cost is limited because
> the same mutex was also acquired shortly before in __bprm_mm_init(),
> so it is hot and uncontended.
>

Well, it isn't cost-free. find_vma() is called a lot and a surprising
number of systems apparently run with CONFIG_DEBUG_VM. Why do you
think this cost is justified?