mm: clean up anon_vma implementation
Status from this message: [merged mm-stable] mm-rmap-separate-out-fork-only-logic-on-anon_vma_clone.patch removed from -mm tree
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v3 Latest9 patches 1 replyApplied 9/9
- v28 patches 23 repliesSuperseded
- v18 patches 30 repliesSuperseded
Changes in v3 from the cover letter
* Propagate tags (thanks everyone!)
* Fold fix-patches into series.
* Add fix for syzbot report about an accursed partially-initialised VMA fault injection error path.
* Fixed a typo, a comment whitespace error I noticed and add some comments to anon_vma_fork(), set anon_vma->num_active_vmas = 1 to make it clear that we're setting this on a newly allocated anon_vma.
Patches in v3 All 9 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/9 | mm/rmap: improve anon_vma_clone(), unlink_anon_vmas() comments, add assertsmm/ | +107 | 0 replies | Applied |
| 2/9 | mm/rmap: eliminate partial anon_vma tear-down in anon_vma_fork()mm/ | +24 | 0 replies | Applied |
| 3/9 | mm/rmap: skip unfaulted VMAs on anon_vma clone, unlinkmm/ | +13 | 0 replies | Applied |
| 4/9 | mm/rmap: remove unnecessary root lock dance in anon_vma clone, unmapmm/ | +15 | 0 replies | Applied |
| 5/9 | mm/rmap: remove anon_vma_merge() functioninclude/ mm/ tools/ | +1 | 0 replies | Applied |
| 6/9 | mm/rmap: make anon_vma functions internalinclude/ mm/ | +58 | 0 replies | Applied |
| 7/9 | mm/mmap_lock: add vma_is_attached() helperinclude/ | +7 | 0 replies | Applied |
| 8/9 | mm/rmap: allocate anon_vma_chain objects unlocked when possiblemm/ | +37 | 0 replies | Applied |
| 9/9 | mm/rmap: separate out fork-only logic on anon_vma_clone()mm/ mm/ mm/ +1 more | +74 | 0 replies | Applied |
Reviews trailers per patch
8 of 9 patches have a Reviewed-by or Acked-by.
| Patch | Liam R. Howlett | Suren Baghdasaryan |
|---|---|---|
| 1/9 | R-b | |
| 2/9 | ||
| 3/9 | R-b | R-b |
| 4/9 | R-b | |
| 5/9 | R-b | R-b |
| 6/9 | R-b | R-b |
| 7/9 | R-b | R-b |
| 8/9 | R-b | R-b |
| 9/9 | R-b | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v3 0/9] mm: clean up anon_vma implementation
The anon_vma logic is hugely confusing and, much like a bundle of wires entangled with one another, pulling on one thread seems only to lead to more entanglement elsewhere.
There is a mish-mash of the core implementation, how that implementation is invoked, how helper functions are invoked and concepts such as adjacent anon_vma merge and anon_vma object reuse.
This series tries to improve the situation somewhat.
It starts by establishing some invariants in the core anon_vma_clone() and unlink_anon_vmas() functions, largely expressed via VM_WARN_ON_ONCE() asserts.
These act as some form of self-documentation as to the conditions we find ourselves in when invoking these functions.
We also add kdoc comments for anon_vma_clone() and unlink_anon_vmas().
We then update anon_vma_fork() to avoid passing a partially set up (and thus invalid) VMA to unlink_anon_vmas() - functions which are used both for partially set up and valid data types has historically been the source of a lot of confusion and bugs.
We then makes use of the established known conditions to directly skip unfaulted VMAs (rather than implicitly via an empty vma->anon_vma_chain list).
We remove the confusing anon_vma_merge() function (we already have a concept of anon_vma merge in that we merge anon_vma's that would otherwise be compatible except for attributes that mprotect() could change - which anon_vma_merge() has nothing to do with).
We make the anon_vma functions internal to mm as they do not need to be used by any other part of the kernel, which allows for future abstraction without concern about this.
We then reduce the time over which we hold the anon rmap lock in anon_vma_clone(), as it turns out we can allocate anon_vma_chain objects without holding this lock, since the objects are not yet accessible from the rmap.
This should reduce anon_vma lock contention.
This additionally allows us to remove a confusing GFP_NOWAIT, GFP_KERNEL allocation fallback strategy.
Finally, we explicitly indicate which operation is being performed upon anon_vma_clone(), and separate out fork-only logic to make it very clear that anon_vma reuse only occurs on fork.
v3:
* Propagate tags (thanks everyone!)
* Fold fix-patches into series.
* Add fix for syzbot report about an accursed partially-initialised VMA fault injection error path.
* Fixed a typo, a comment whitespace error I noticed and add some comments to anon_vma_fork(), set anon_vma->num_active_vmas = 1 to make it clear that we're setting this on a newly allocated anon_vma.
v2:
* Propagated tags (thanks all!)
* Corrected typo in 1/8 as per Suren.
* Updated commit message in 1/8 to clarify when we use a downgraded read lock in unlink_anon_vmas(), as per Suren.
* Updated !src->anon_vma no-op comment as per Suren.
* When anon_vma_clone() fails to allocate we have thus far been invoking unlink_anon_vmas() to clean up the partially set up VMA. However this means we have to account for this (likely impossible) scenario in the code and prevents further improvements. Resolve by adding a partial cleanup function specifically for this case.
* Fixed various other typos.
* Placed check_anon_vma_clone() before the !src->anon_vma check in anon_vma_clone() in 2/8 as per Suren.
* Retained !vma->anon_vma && !list_empty(&vma->anon_vma_chain) check on unlink_anon_vmas() as per Liam.
* Added comment about anon_vma's sharing same root in 3/8 as per Suren.
* Updated 7/8 to have cleanup_partial_anon_vmas() do even less - since we now allocate AVC's first before inserting into the interval tree we do not need to acquire the lock or do anything special here, just clean up the AVC's.
* Updated commit messages as necessary.
* Renamed find_reusable_anon_vma() to try_to_reuse_anon_vma() for clarity as per Suren.
* Added a new assert to check_anon_vma_clone() to make it clear that, when not forking, we expect dst->anon_vma to be set.
* Renamed vma to dst in try_to_reuse_anon_vma() to make it clear that we're checking/manipulating the destination VMA.
https://lore.kernel.org/all/[email protected]/
v1:
https://lore.kernel.org/all/[email protected]/
Lorenzo Stoakes (9):
mm/rmap: improve anon_vma_clone(), unlink_anon_vmas() comments, add
asserts
mm/rmap: eliminate partial anon_vma tear-down in anon_vma_fork() mm/rmap: skip unfaulted VMAs on anon_vma clone, unlink mm/rmap: remove unnecessary root lock dance in anon_vma clone, unmap mm/rmap: remove anon_vma_merge() function
mm/rmap: make anon_vma functions internal
mm/mmap_lock: add vma_is_attached() helper
mm/rmap: allocate anon_vma_chain objects unlocked when possible mm/rmap: separate out fork-only logic on anon_vma_clone()
include/linux/mmap_lock.h | 9 +- include/linux/rmap.h | 67 ------- mm/internal.h | 67 +++++++ mm/rmap.c | 315 ++++++++++++++++++++----------- mm/vma.c | 8 +- tools/testing/vma/vma_internal.h | 16 +- 6 files changed, 288 insertions(+), 194 deletions(-)
--
2.52.0