[PATCH v3 0/3] Use killable vma write locking in most places

From: Suren Baghdasaryan

Date: Thu Feb 26 2026 - 02:07:26 EST


Now that we have vma_start_write_killable() we can replace most of the
vma_start_write() calls with it, improving reaction time to the kill
signal.

There are several places which are left untouched by this patchset:

1. free_pgtables() because function should free page tables even if a
fatal signal is pending.

2. userfaultd code, where some paths calling vma_start_write() can
handle EINTR and some can't without a deeper code refactoring.

3. mpol_rebind_mm() which is used by cpusset controller for migrations
and operates on a remote mm. Incomplete operations here would result
in an inconsistent cgroup state.

4. vm_flags_{set|mod|clear} require refactoring that involves moving
vma_start_write() out of these functions and replacing it with
vma_assert_write_locked(), then callers of these functions should
lock the vma themselves using vma_start_write_killable() whenever
possible.

A cleanup patch is added in the beginning to make later changes more
readable. The second patch contains most of the changes and the last
patch contains the changes associated with process_vma_walk_lock()
error handling.

Changes since v2 [1]:
- rebased over mm-unstable, per Matthew Wilcox;
- removed mpol_rebind_mm() changes since the function operates on a
remote mm and incomplete operation can leave unrelated process in an
inconsistent state;
- moved vma_start_write_killable() inside set_mempolicy_home_node() to
avoid locking extra vmas, per Liam R. Howlett
- moved vma_start_write_killable() inside __mmap_new_vma() to lock the
vma right after it's allocation, per Liam R. Howlett
- introduced VMA_MERGE_ERROR_INTR to add EINTR handling for vma_modify()
- changed do_mbind() error handling for avoid EINTR overrides;
- changed migrate_to_node() error handling for avoid EINTR overrides;
- added EINTR handling in queue_pages_range();
- fixed clear_refs_write() error handling which previous verstion broke
by skipping some of the cleanup logic;

[1] https://lore.kernel.org/all/20260217163250.2326001-1-surenb@xxxxxxxxxx/

Suren Baghdasaryan (3):
mm/vma: cleanup error handling path in vma_expand()
mm: replace vma_start_write() with vma_start_write_killable()
mm: use vma_start_write_killable() in process_vma_walk_lock()

arch/powerpc/kvm/book3s_hv_uvmem.c | 5 +-
arch/s390/kvm/kvm-s390.c | 2 +-
fs/proc/task_mmu.c | 5 +-
mm/khugepaged.c | 5 +-
mm/madvise.c | 4 +-
mm/memory.c | 2 +
mm/mempolicy.c | 22 +++--
mm/mlock.c | 21 +++--
mm/mprotect.c | 4 +-
mm/mremap.c | 4 +-
mm/pagewalk.c | 20 +++--
mm/vma.c | 127 ++++++++++++++++++++---------
mm/vma.h | 6 ++
mm/vma_exec.c | 6 +-
14 files changed, 167 insertions(+), 66 deletions(-)


base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
--
2.53.0.414.gf7e9f6c205-goog