android_kernel_motorola_sm6225/mm
Suren Baghdasaryan 0dfd96ad52 BACKPORT: FROMLIST: mm: protect free_pgtables with mmap_lock write lock in exit_mmap
oom-reaper and process_mrelease system call should protect against
races with exit_mmap which can destroy page tables while they
walk the VMA tree. oom-reaper protects from that race by setting
MMF_OOM_VICTIM and by relying on exit_mmap to set MMF_OOM_SKIP
before taking and releasing mmap_write_lock. process_mrelease has
to elevate mm->mm_users to prevent such race. Both oom-reaper and
process_mrelease hold mmap_read_lock when walking the VMA tree.
The locking rules and mechanisms could be simpler if exit_mmap takes
mmap_write_lock while executing destructive operations such as
free_pgtables.
Change exit_mmap to hold the mmap_write_lock when calling
free_pgtables. Operations like unmap_vmas() and unlock_range() are not
destructive and could run under mmap_read_lock but for simplicity we
take one mmap_write_lock during almost the entire operation. Note
also that because oom-reaper checks VM_LOCKED flag, unlock_range()
should not be allowed to race with it.
In most cases this lock should be uncontended. Previously, Kirill
reported ~4% regression caused by a similar change [1]. We reran the
same test and although the individual results are quite noisy, the
percentiles show lower regression with 1.6% being the worst case [2].
The change allows oom-reaper and process_mrelease to execute safely
under mmap_read_lock without worries that exit_mmap might destroy page
tables from under them.

[1] https://lore.kernel.org/all/20170725141723.ivukwhddk2voyhuc@node.shutemov.name/
[2] https://lore.kernel.org/all/CAJuCfpGC9-c9P40x7oy=jy5SphMcd0o0G_6U1-+JAziGKG6dGA@mail.gmail.com/

Signed-off-by: Suren Baghdasaryan <surenb@google.com>

Link: https://lore.kernel.org/all/20211124235906.14437-1-surenb@google.com/

Bug: 130172058
Bug: 189803002
Change-Id: Ic87272d09a0b68a1b0e968e8f1a1510fd6fc776a
Git-commit: 28358ebf2adb31117893813992fefcfd359a6a16
Git-repo: https://android.googlesource.com/kernel/common/
[quic_gkohli@quicinc.com: Resolved cherry-pick conflict in mm/mmap.c due
 to mmap lock was implemented differently in older kernel, and
 Although process_mrelease is not applicable in older kernel, but this
 patch is required to take exclusive lock in exit_mmap path so that
 SPF knows an isolated vma was freed from this path]
Signed-off-by: Gaurav Kohli <quic_gkohli@quicinc.com>
Signed-off-by: Srinivasarao Pathipati <quic_c_spathi@quicinc.com>
2023-08-11 14:44:57 +05:30
..
kasan Merge android-4.19.78 (75337a6) into msm-4.19 2020-03-16 23:09:43 -07:00
backing-dev.c
balloon_compaction.c
bootmem.c
cleancache.c
cma.c mm: cma: Print correct request pages 2021-03-02 18:45:12 +08:00
cma.h
cma_debug.c mm: cma: make writeable CMA debugfs optional 2019-08-06 12:35:54 +05:30
compaction.c Reverting below patches from android-4.19-stable.125 2020-07-29 13:12:56 +05:30
debug.c
debug_page_ref.c
dmapool.c UPSTREAM: mm: security: introduce init_on_alloc=1 and init_on_free=1 boot options 2019-08-30 11:58:12 +02:00
early_ioremap.c
fadvise.c
failslab.c
filemap.c ANDROID: mm/filemap: Fix missing put_page() for speculative page fault 2023-03-27 09:31:53 -07:00
frame_vector.c UPSTREAM: mm: untag user pointers in get_vaddr_frames 2019-10-07 15:27:40 -04:00
frontswap.c
gup.c gup: document and work around "COW can break either way" issue 2022-07-22 14:44:55 +05:30
gup_benchmark.c mm/gup_benchmark.c: prevent integer overflow in ioctl 2019-12-01 09:17:07 +01:00
highmem.c
hmm.c mm/memory_hotplug: shrink zones when offlining memory 2020-01-29 16:43:27 +01:00
huge_memory.c gup: document and work around "COW can break either way" issue 2022-07-22 14:44:55 +05:30
hugetlb.c Merge android-4.19-stable.146 (443485d) into msm-4.19 2020-10-16 11:06:31 +05:30
hugetlb_cgroup.c mm: hugetlb: switch to css_tryget() in hugetlb_cgroup_charge_cgroup() 2019-11-20 18:45:20 +01:00
hwpoison-inject.c
init-mm.c
internal.h Reverting below patches from android-4.19-stable.125 2020-07-29 13:12:56 +05:30
interval_tree.c
Kconfig mm/Kconfig: forcing allocators to return ZONE_DMA32 memory 2020-09-29 09:15:00 -07:00
Kconfig.debug mm, oom: Modify default value of panic_on_oom 2019-06-04 12:17:56 -07:00
khugepaged.c ANDROID: mm/khugepaged: add missing vm_write_{begin|end} 2023-03-14 18:59:12 +05:30
kmemleak-test.c
kmemleak.c Merge android-4.19-stable.149 (9ce79d9) into msm-4.19 2020-10-21 09:25:49 +05:30
ksm.c Merge android-4.19-stable.125 (a483478) into msm-4.19 2020-09-20 23:45:10 +05:30
list_lru.c mm/list_lru.c: fix memory leak in __memcg_init_list_lru_node 2019-06-19 08:17:59 +02:00
maccess.c uaccess: Add non-pagefault user-space write function 2020-09-09 19:04:29 +02:00
madvise.c Merge android-4.19.95 (5da1114) into msm-4.19 2020-03-27 10:48:20 -07:00
Makefile Merge android-4.19-stable.125 (a483478) into msm-4.19 2020-09-20 23:45:10 +05:30
memblock.c Merge android-4.19-stable.125 (a483478) into msm-4.19 2020-09-20 23:45:10 +05:30
memcontrol.c mm/memcg: fix device private memcg accounting 2020-10-29 09:55:15 +01:00
memfd.c This is the 4.19.85 stable release 2019-11-20 20:43:17 +01:00
memory-failure.c Merge android-4.19-q.81 (9045ee1) into msm-4.19 2019-10-29 04:52:53 -07:00
memory.c ANDROID: mm: fix invalid backport in speculative page fault path 2023-03-14 20:08:39 +05:30
memory_hotplug.c Merge android-4.19-stable.152 (13abe23) into msm-4.19 2020-10-28 17:52:20 +05:30
mempolicy.c ANDROID: mm: remove sequence counting when mmap_lock is not exclusively owned 2023-03-14 19:10:30 +05:30
mempool.c
memtest.c
migrate.c Merge android-4.19.110 (1984fff) into msm-4.19 2020-05-23 05:08:22 -07:00
mincore.c UPSTREAM: mm: untag user pointers passed to memory syscalls 2019-10-07 15:27:40 -04:00
mlock.c Merge android-4.19.95 (5da1114) into msm-4.19 2020-03-27 10:48:20 -07:00
mm_event.c ANDROID: GKI: support mm_event for FS/IO/UFS path 2020-05-30 00:09:49 +00:00
mm_init.c
mmap.c BACKPORT: FROMLIST: mm: protect free_pgtables with mmap_lock write lock in exit_mmap 2023-08-11 14:44:57 +05:30
mmu_context.c
mmu_notifier.c mm/mmu_notifier: use hlist_add_head_rcu() 2019-07-31 07:27:08 +02:00
mmzone.c ANDROID: GKI: mm: Export symbols __next_zones_zonelist and zone_watermark_ok_safe 2020-04-10 02:39:42 +00:00
mprotect.c Merge android-4.19.110 (1984fff) into msm-4.19 2020-05-23 05:08:22 -07:00
mremap.c ANDROID: mm: use raw seqcount variants in vm_write_* 2021-10-21 22:57:43 -07:00
msync.c UPSTREAM: mm: untag user pointers passed to memory syscalls 2019-10-07 15:27:40 -04:00
nobootmem.c
nommu.c x86/mm: split vmalloc_sync_all() 2020-03-25 08:06:13 +01:00
oom_kill.c mm, oom_adj: don't loop through tasks in __set_oom_adj when not necessary 2020-10-29 09:55:15 +01:00
page-writeback.c mm/page-writeback.c: avoid potential division by zero in wb_min_max_ratio() 2020-01-23 08:21:31 +01:00
page_alloc.c Merge android-4.19-stable.152 (13abe23) into msm-4.19 2020-10-28 17:52:20 +05:30
page_counter.c mm/page_counter.c: fix protection usage propagation 2020-08-21 11:05:33 +02:00
page_ext.c mm: fix the page_owner initializing issue for arm32 2020-09-02 16:37:28 +08:00
page_idle.c mm/page_idle.c: fix oops because end_pfn is larger than max_pfn 2019-07-03 13:14:45 +02:00
page_io.c Merge android-4.19.110 (1984fff) into msm-4.19 2020-05-23 05:08:22 -07:00
page_isolation.c
page_owner.c Merge "Merge android-4.19-q.81 (9045ee1) into msm-4.19" 2019-11-06 06:40:33 -08:00
page_poison.c Merge android-4.19.95 (5da1114) into msm-4.19 2020-03-27 10:48:20 -07:00
page_vma_mapped.c
pagewalk.c mm: pagewalk: fix termination condition in walk_pte_range() 2020-10-01 13:14:32 +02:00
percpu-internal.h
percpu-km.c
percpu-stats.c
percpu-vm.c
percpu.c This is the 4.19.147 stable release 2020-09-24 12:48:04 +02:00
pgtable-generic.c
process_reclaim.c mm: process_reclaim: allow nomap-only reclaim 2020-07-02 04:35:02 -07:00
process_vm_access.c
quicklist.c
readahead.c Fixing Android Net Test compilation 2020-03-21 18:06:06 -07:00
rmap.c Merge android-4.19-q.68 (f3e9c9b) into msm-4.19 2019-08-28 23:55:13 -07:00
rodata_test.c
shmem.c Merge android-4.19-stable.125 (a483478) into msm-4.19 2020-09-20 23:45:10 +05:30
showmem.c
slab.c UPSTREAM: mm, slab: combine kmalloc_caches and kmalloc_dma_caches 2019-12-13 14:04:05 -08:00
slab.h UPSTREAM: kasan, kmemleak: pass tagged pointers to kmemleak 2019-09-24 17:44:14 -07:00
slab_common.c This is the 4.19.135 stable release 2020-07-29 13:22:30 +02:00
slob.c UPSTREAM: mm/sl[uo]b: export __kmalloc_track(_node)_caller 2020-11-02 16:12:14 +00:00
slub.c Merge android-4.19-stable.157 (8ee67bc) into msm-4.19 2020-12-18 18:35:06 +05:30
sparse-vmemmap.c
sparse.c mm/memory_hotplug: remove "zone" parameter from sparse_remove_one_section 2020-01-29 16:43:26 +01:00
swap.c Merge android-4.19.63 (75ff56e) into msm-4.19 2019-08-13 01:20:38 -07:00
swap_cgroup.c
swap_ratio.c
swap_slots.c mm: swap: Add null pointer check 2019-06-18 12:45:01 -07:00
swap_state.c Merge android-4.19-stable.149 (9ce79d9) into msm-4.19 2020-10-21 09:25:49 +05:30
swapfile.c Merge android-4.19-stable.149 (9ce79d9) into msm-4.19 2020-10-21 09:25:49 +05:30
truncate.c
usercopy.c Merge android-4.19-q.79 (40321f2) into msm-4.19 2019-10-21 05:07:30 -07:00
userfaultfd.c
util.c This is the 4.19.129 stable release 2020-06-22 10:50:54 +02:00
vmacache.c
vmalloc.c Merge android-4.19-stable.125 (a483478) into msm-4.19 2020-09-20 23:45:10 +05:30
vmpressure.c Merge android-4.19-q.80 (fd673e8) into msm-4.19 2019-10-21 05:33:39 -07:00
vmscan.c Merge android-4.19-stable.149 (9ce79d9) into msm-4.19 2020-10-21 09:25:49 +05:30
vmstat.c Merge android-4.19-stable.136 (204dd19) into msm-4.19 2020-10-14 20:04:29 +05:30
workingset.c
z3fold.c
zbud.c
zpool.c
zsmalloc.c Merge android-4.19-q.94 (dabb11d) into msm-4.19 2020-02-03 21:41:48 -08:00
zswap.c