Re: [RFC PATCH] docs/mm: add VMA locks documentation

From: Hillf Danton
Date: Thu Nov 07 2024 - 06:07:51 EST


On Fri, 1 Nov 2024 18:50:33 +0000 Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
>
> Locking around VMAs is complicated and confusing. While we have a number of
> disparate comments scattered around the place, we seem to be reaching a
> level of complexity that justifies a serious effort at clearly documenting
> how locks are expected to be interacted with when it comes to interacting
> with mm_struct and vm_area_struct objects.
>
> This is especially pertinent as regards efforts to find sensible
> abstractions for these fundamental objects within the kernel rust
> abstraction whose compiler strictly requires some means of expressing these
> rules (and through this expression can help self-document these
> requirements as well as enforce them which is an exciting concept).
>
> The document limits scope to mmap and VMA locks and those that are
> immediately adjacent and relevant to them - so additionally covers page
> table locking as this is so very closely tied to VMA operations (and relies
> upon us handling these correctly).
>
> The document tries to cover some of the nastier and more confusing edge
> cases and concerns especially around lock ordering and page table teardown.
>
What is missed is the clear guide to the correct locking order.
Is the order below correct for instance?

lock vma
lock vma->vm_mm